1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Keep this file in sync with entry_kernel.h.
7 #include "sync/syncable/syncable_enum_conversions.h"
9 #include "base/basictypes.h"
10 #include "base/logging.h"
15 // We can't tokenize expected_min/expected_max since it can be a
16 // general expression.
17 #define ASSERT_ENUM_BOUNDS(enum_min, enum_max, expected_min, expected_max) \
18 COMPILE_ASSERT(static_cast<int>(enum_min) == \
19 static_cast<int>(expected_min), \
20 enum_min##_not_expected_min); \
21 COMPILE_ASSERT(static_cast<int>(enum_max) == \
22 static_cast<int>(expected_max), \
23 enum_max##_not_expected_max);
25 #define ENUM_CASE(enum_value) case enum_value: return #enum_value
27 const char* GetMetahandleFieldString(MetahandleField metahandle_field
) {
28 ASSERT_ENUM_BOUNDS(META_HANDLE
, META_HANDLE
,
29 INT64_FIELDS_BEGIN
, BASE_VERSION
- 1);
30 switch (metahandle_field
) {
31 ENUM_CASE(META_HANDLE
);
37 const char* GetBaseVersionString(BaseVersion base_version
) {
38 ASSERT_ENUM_BOUNDS(BASE_VERSION
, BASE_VERSION
,
39 META_HANDLE
+ 1, SERVER_VERSION
- 1);
40 switch (base_version
) {
41 ENUM_CASE(BASE_VERSION
);
47 const char* GetInt64FieldString(Int64Field int64_field
) {
48 ASSERT_ENUM_BOUNDS(SERVER_VERSION
, TRANSACTION_VERSION
,
49 BASE_VERSION
+ 1, INT64_FIELDS_END
- 1);
50 switch (int64_field
) {
51 ENUM_CASE(SERVER_VERSION
);
52 ENUM_CASE(LOCAL_EXTERNAL_ID
);
53 ENUM_CASE(TRANSACTION_VERSION
);
54 case INT64_FIELDS_END
: break;
60 const char* GetTimeFieldString(TimeField time_field
) {
61 ASSERT_ENUM_BOUNDS(MTIME
, SERVER_CTIME
,
62 TIME_FIELDS_BEGIN
, TIME_FIELDS_END
- 1);
65 ENUM_CASE(SERVER_MTIME
);
67 ENUM_CASE(SERVER_CTIME
);
68 case TIME_FIELDS_END
: break;
74 const char* GetIdFieldString(IdField id_field
) {
75 ASSERT_ENUM_BOUNDS(ID
, SERVER_PARENT_ID
,
76 ID_FIELDS_BEGIN
, ID_FIELDS_END
- 1);
80 ENUM_CASE(SERVER_PARENT_ID
);
81 case ID_FIELDS_END
: break;
87 const char* GetIndexedBitFieldString(IndexedBitField indexed_bit_field
) {
88 ASSERT_ENUM_BOUNDS(IS_UNSYNCED
, IS_UNAPPLIED_UPDATE
,
89 BIT_FIELDS_BEGIN
, INDEXED_BIT_FIELDS_END
- 1);
90 switch (indexed_bit_field
) {
91 ENUM_CASE(IS_UNSYNCED
);
92 ENUM_CASE(IS_UNAPPLIED_UPDATE
);
93 case INDEXED_BIT_FIELDS_END
: break;
99 const char* GetIsDelFieldString(IsDelField is_del_field
) {
100 ASSERT_ENUM_BOUNDS(IS_DEL
, IS_DEL
,
101 INDEXED_BIT_FIELDS_END
, IS_DIR
- 1);
102 switch (is_del_field
) {
109 const char* GetBitFieldString(BitField bit_field
) {
110 ASSERT_ENUM_BOUNDS(IS_DIR
, SERVER_IS_DEL
,
111 IS_DEL
+ 1, BIT_FIELDS_END
- 1);
114 ENUM_CASE(SERVER_IS_DIR
);
115 ENUM_CASE(SERVER_IS_DEL
);
116 case BIT_FIELDS_END
: break;
122 const char* GetStringFieldString(StringField string_field
) {
123 ASSERT_ENUM_BOUNDS(NON_UNIQUE_NAME
, UNIQUE_BOOKMARK_TAG
,
124 STRING_FIELDS_BEGIN
, STRING_FIELDS_END
- 1);
125 switch (string_field
) {
126 ENUM_CASE(NON_UNIQUE_NAME
);
127 ENUM_CASE(SERVER_NON_UNIQUE_NAME
);
128 ENUM_CASE(UNIQUE_SERVER_TAG
);
129 ENUM_CASE(UNIQUE_CLIENT_TAG
);
130 ENUM_CASE(UNIQUE_BOOKMARK_TAG
);
131 case STRING_FIELDS_END
: break;
137 const char* GetProtoFieldString(ProtoField proto_field
) {
138 ASSERT_ENUM_BOUNDS(SPECIFICS
, BASE_SERVER_SPECIFICS
,
139 PROTO_FIELDS_BEGIN
, PROTO_FIELDS_END
- 1);
140 switch (proto_field
) {
141 ENUM_CASE(SPECIFICS
);
142 ENUM_CASE(SERVER_SPECIFICS
);
143 ENUM_CASE(BASE_SERVER_SPECIFICS
);
144 case PROTO_FIELDS_END
: break;
150 const char* GetUniquePositionFieldString(UniquePositionField position_field
) {
151 ASSERT_ENUM_BOUNDS(SERVER_UNIQUE_POSITION
, UNIQUE_POSITION
,
152 UNIQUE_POSITION_FIELDS_BEGIN
,
153 UNIQUE_POSITION_FIELDS_END
- 1);
154 switch(position_field
) {
155 ENUM_CASE(SERVER_UNIQUE_POSITION
);
156 ENUM_CASE(UNIQUE_POSITION
);
157 case UNIQUE_POSITION_FIELDS_END
: break;
163 const char* GetAttachmentMetadataFieldString(
164 AttachmentMetadataField attachment_metadata_field
) {
165 ASSERT_ENUM_BOUNDS(ATTACHMENT_METADATA
,
166 SERVER_ATTACHMENT_METADATA
,
167 ATTACHMENT_METADATA_FIELDS_BEGIN
,
168 ATTACHMENT_METADATA_FIELDS_END
- 1);
169 switch(attachment_metadata_field
) {
170 ENUM_CASE(ATTACHMENT_METADATA
);
171 ENUM_CASE(SERVER_ATTACHMENT_METADATA
);
172 case ATTACHMENT_METADATA_FIELDS_END
: break;
178 const char* GetBitTempString(BitTemp bit_temp
) {
179 ASSERT_ENUM_BOUNDS(SYNCING
, SYNCING
,
180 BIT_TEMPS_BEGIN
, BIT_TEMPS_END
- 1);
183 case BIT_TEMPS_END
: break;
190 #undef ASSERT_ENUM_BOUNDS
192 } // namespace syncable
193 } // namespace syncer