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
, NEXT_ID
,
76 ID_FIELDS_BEGIN
, ID_FIELDS_END
- 1);
80 ENUM_CASE(SERVER_PARENT_ID
);
83 case ID_FIELDS_END
: break;
89 const char* GetIndexedBitFieldString(IndexedBitField indexed_bit_field
) {
90 ASSERT_ENUM_BOUNDS(IS_UNSYNCED
, IS_UNAPPLIED_UPDATE
,
91 BIT_FIELDS_BEGIN
, INDEXED_BIT_FIELDS_END
- 1);
92 switch (indexed_bit_field
) {
93 ENUM_CASE(IS_UNSYNCED
);
94 ENUM_CASE(IS_UNAPPLIED_UPDATE
);
95 case INDEXED_BIT_FIELDS_END
: break;
101 const char* GetIsDelFieldString(IsDelField is_del_field
) {
102 ASSERT_ENUM_BOUNDS(IS_DEL
, IS_DEL
,
103 INDEXED_BIT_FIELDS_END
, IS_DIR
- 1);
104 switch (is_del_field
) {
111 const char* GetBitFieldString(BitField bit_field
) {
112 ASSERT_ENUM_BOUNDS(IS_DIR
, SERVER_IS_DEL
,
113 IS_DEL
+ 1, BIT_FIELDS_END
- 1);
116 ENUM_CASE(SERVER_IS_DIR
);
117 ENUM_CASE(SERVER_IS_DEL
);
118 case BIT_FIELDS_END
: break;
124 const char* GetStringFieldString(StringField string_field
) {
125 ASSERT_ENUM_BOUNDS(NON_UNIQUE_NAME
, UNIQUE_CLIENT_TAG
,
126 STRING_FIELDS_BEGIN
, STRING_FIELDS_END
- 1);
127 switch (string_field
) {
128 ENUM_CASE(NON_UNIQUE_NAME
);
129 ENUM_CASE(SERVER_NON_UNIQUE_NAME
);
130 ENUM_CASE(UNIQUE_SERVER_TAG
);
131 ENUM_CASE(UNIQUE_CLIENT_TAG
);
132 case STRING_FIELDS_END
: break;
138 const char* GetProtoFieldString(ProtoField proto_field
) {
139 ASSERT_ENUM_BOUNDS(SPECIFICS
, BASE_SERVER_SPECIFICS
,
140 PROTO_FIELDS_BEGIN
, PROTO_FIELDS_END
- 1);
141 switch (proto_field
) {
142 ENUM_CASE(SPECIFICS
);
143 ENUM_CASE(SERVER_SPECIFICS
);
144 ENUM_CASE(BASE_SERVER_SPECIFICS
);
145 case PROTO_FIELDS_END
: break;
151 const char* GetOrdinalFieldString(OrdinalField ordinal_field
) {
152 ASSERT_ENUM_BOUNDS(SERVER_ORDINAL_IN_PARENT
, SERVER_ORDINAL_IN_PARENT
,
153 ORDINAL_FIELDS_BEGIN
, ORDINAL_FIELDS_END
- 1);
154 switch(ordinal_field
) {
155 ENUM_CASE(SERVER_ORDINAL_IN_PARENT
);
156 case ORDINAL_FIELDS_END
: break;
162 const char* GetBitTempString(BitTemp bit_temp
) {
163 ASSERT_ENUM_BOUNDS(SYNCING
, SYNCING
,
164 BIT_TEMPS_BEGIN
, BIT_TEMPS_END
- 1);
167 case BIT_TEMPS_END
: break;
174 #undef ASSERT_ENUM_BOUNDS
176 } // namespace syncable
177 } // namespace syncer