1 // Copyright (c) 2011 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. 4 5 // Keep this file in sync with syncable.h. 6 7 #include "chrome/browser/sync/syncable/syncable_enum_conversions.h" 8 9 #include "base/basictypes.h" 10 #include "base/logging.h" 11 12 namespace syncable { 13 14 // We can't tokenize expected_min/expected_max since it can be a 15 // general expression. 16 #define ASSERT_ENUM_BOUNDS(enum_min, enum_max, expected_min, expected_max) \ 17 COMPILE_ASSERT(static_cast<int>(enum_min) == \ 18 static_cast<int>(expected_min), \ 19 enum_min##_not_expected_min); \ 20 COMPILE_ASSERT(static_cast<int>(enum_max) == \ 21 static_cast<int>(expected_max), \ 22 enum_max##_not_expected_max); 23 24 #define ENUM_CASE(enum_value) case enum_value: return #enum_value 25 26 const char* GetMetahandleFieldString(MetahandleField metahandle_field) { 27 ASSERT_ENUM_BOUNDS(META_HANDLE, META_HANDLE, 28 INT64_FIELDS_BEGIN, BASE_VERSION - 1); 29 switch (metahandle_field) { 30 ENUM_CASE(META_HANDLE); 31 } 32 NOTREACHED(); 33 return ""; 34 } 35 36 const char* GetBaseVersionString(BaseVersion base_version) { 37 ASSERT_ENUM_BOUNDS(BASE_VERSION, BASE_VERSION, 38 META_HANDLE + 1, SERVER_VERSION - 1); 39 switch (base_version) { 40 ENUM_CASE(BASE_VERSION); 41 } 42 NOTREACHED(); 43 return ""; 44 } 45 46 const char* GetInt64FieldString(Int64Field int64_field) { 47 ASSERT_ENUM_BOUNDS(SERVER_VERSION, LOCAL_EXTERNAL_ID, 48 BASE_VERSION + 1, INT64_FIELDS_END - 1); 49 switch (int64_field) { 50 ENUM_CASE(SERVER_VERSION); 51 ENUM_CASE(MTIME); 52 ENUM_CASE(SERVER_MTIME); 53 ENUM_CASE(CTIME); 54 ENUM_CASE(SERVER_CTIME); 55 ENUM_CASE(SERVER_POSITION_IN_PARENT); 56 ENUM_CASE(LOCAL_EXTERNAL_ID); 57 case INT64_FIELDS_END: break; 58 } 59 NOTREACHED(); 60 return ""; 61 } 62 63 const char* GetIdFieldString(IdField id_field) { 64 ASSERT_ENUM_BOUNDS(ID, NEXT_ID, 65 ID_FIELDS_BEGIN, ID_FIELDS_END - 1); 66 switch (id_field) { 67 ENUM_CASE(ID); 68 ENUM_CASE(PARENT_ID); 69 ENUM_CASE(SERVER_PARENT_ID); 70 ENUM_CASE(PREV_ID); 71 ENUM_CASE(NEXT_ID); 72 case ID_FIELDS_END: break; 73 } 74 NOTREACHED(); 75 return ""; 76 } 77 78 const char* GetIndexedBitFieldString(IndexedBitField indexed_bit_field) { 79 ASSERT_ENUM_BOUNDS(IS_UNSYNCED, IS_UNAPPLIED_UPDATE, 80 BIT_FIELDS_BEGIN, INDEXED_BIT_FIELDS_END - 1); 81 switch (indexed_bit_field) { 82 ENUM_CASE(IS_UNSYNCED); 83 ENUM_CASE(IS_UNAPPLIED_UPDATE); 84 case INDEXED_BIT_FIELDS_END: break; 85 } 86 NOTREACHED(); 87 return ""; 88 } 89 90 const char* GetIsDelFieldString(IsDelField is_del_field) { 91 ASSERT_ENUM_BOUNDS(IS_DEL, IS_DEL, 92 INDEXED_BIT_FIELDS_END, IS_DIR - 1); 93 switch (is_del_field) { 94 ENUM_CASE(IS_DEL); 95 } 96 NOTREACHED(); 97 return ""; 98 } 99 100 const char* GetBitFieldString(BitField bit_field) { 101 ASSERT_ENUM_BOUNDS(IS_DIR, SERVER_IS_DEL, 102 IS_DEL + 1, BIT_FIELDS_END - 1); 103 switch (bit_field) { 104 ENUM_CASE(IS_DIR); 105 ENUM_CASE(SERVER_IS_DIR); 106 ENUM_CASE(SERVER_IS_DEL); 107 case BIT_FIELDS_END: break; 108 } 109 NOTREACHED(); 110 return ""; 111 } 112 113 const char* GetStringFieldString(StringField string_field) { 114 ASSERT_ENUM_BOUNDS(NON_UNIQUE_NAME, UNIQUE_CLIENT_TAG, 115 STRING_FIELDS_BEGIN, STRING_FIELDS_END - 1); 116 switch (string_field) { 117 ENUM_CASE(NON_UNIQUE_NAME); 118 ENUM_CASE(SERVER_NON_UNIQUE_NAME); 119 ENUM_CASE(UNIQUE_SERVER_TAG); 120 ENUM_CASE(UNIQUE_CLIENT_TAG); 121 case STRING_FIELDS_END: break; 122 } 123 NOTREACHED(); 124 return ""; 125 } 126 127 const char* GetProtoFieldString(ProtoField proto_field) { 128 ASSERT_ENUM_BOUNDS(SPECIFICS, SERVER_SPECIFICS, 129 PROTO_FIELDS_BEGIN, PROTO_FIELDS_END - 1); 130 switch (proto_field) { 131 ENUM_CASE(SPECIFICS); 132 ENUM_CASE(SERVER_SPECIFICS); 133 case PROTO_FIELDS_END: break; 134 } 135 NOTREACHED(); 136 return ""; 137 } 138 139 const char* GetBitTempString(BitTemp bit_temp) { 140 ASSERT_ENUM_BOUNDS(SYNCING, SYNCING, 141 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); 142 switch (bit_temp) { 143 ENUM_CASE(SYNCING); 144 case BIT_TEMPS_END: break; 145 } 146 NOTREACHED(); 147 return ""; 148 } 149 150 #undef ENUM_CASE 151 #undef ASSERT_ENUM_BOUNDS 152 153 } // namespace syncable 154