Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: components/sync/syncable/syncable_enum_conversions.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Keep this file in sync with entry_kernel.h. 5 // Keep this file in sync with entry_kernel.h.
6 6
7 #include "sync/syncable/syncable_enum_conversions.h" 7 #include "components/sync/syncable/syncable_enum_conversions.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace syncer { 11 namespace syncer {
12 namespace syncable { 12 namespace syncable {
13 13
14 // We can't tokenize expected_min/expected_max since it can be a 14 // We can't tokenize expected_min/expected_max since it can be a
15 // general expression. 15 // general expression.
16 #define ASSERT_ENUM_BOUNDS(enum_min, enum_max, expected_min, expected_max) \ 16 #define ASSERT_ENUM_BOUNDS(enum_min, enum_max, expected_min, expected_max) \
17 static_assert(static_cast<int>(enum_min) == \ 17 static_assert(static_cast<int>(enum_min) == static_cast<int>(expected_min), \
18 static_cast<int>(expected_min), \ 18 #enum_min " not " #expected_min); \
19 #enum_min " not " #expected_min); \ 19 static_assert(static_cast<int>(enum_max) == static_cast<int>(expected_max), \
20 static_assert(static_cast<int>(enum_max) == \
21 static_cast<int>(expected_max), \
22 #enum_max " not " #expected_max); 20 #enum_max " not " #expected_max);
23 21
24 #define ENUM_CASE(enum_value) case enum_value: return #enum_value 22 #define ENUM_CASE(enum_value) \
23 case enum_value: \
24 return #enum_value
25 25
26 const char* GetMetahandleFieldString(MetahandleField metahandle_field) { 26 const char* GetMetahandleFieldString(MetahandleField metahandle_field) {
27 ASSERT_ENUM_BOUNDS(META_HANDLE, META_HANDLE, 27 ASSERT_ENUM_BOUNDS(META_HANDLE, META_HANDLE, INT64_FIELDS_BEGIN,
28 INT64_FIELDS_BEGIN, BASE_VERSION - 1); 28 BASE_VERSION - 1);
29 switch (metahandle_field) { 29 switch (metahandle_field) { ENUM_CASE(META_HANDLE); }
30 ENUM_CASE(META_HANDLE);
31 }
32 NOTREACHED(); 30 NOTREACHED();
33 return ""; 31 return "";
34 } 32 }
35 33
36 const char* GetBaseVersionString(BaseVersion base_version) { 34 const char* GetBaseVersionString(BaseVersion base_version) {
37 ASSERT_ENUM_BOUNDS(BASE_VERSION, BASE_VERSION, 35 ASSERT_ENUM_BOUNDS(BASE_VERSION, BASE_VERSION, META_HANDLE + 1,
38 META_HANDLE + 1, SERVER_VERSION - 1); 36 SERVER_VERSION - 1);
39 switch (base_version) { 37 switch (base_version) { ENUM_CASE(BASE_VERSION); }
40 ENUM_CASE(BASE_VERSION);
41 }
42 NOTREACHED(); 38 NOTREACHED();
43 return ""; 39 return "";
44 } 40 }
45 41
46 const char* GetInt64FieldString(Int64Field int64_field) { 42 const char* GetInt64FieldString(Int64Field int64_field) {
47 ASSERT_ENUM_BOUNDS(SERVER_VERSION, TRANSACTION_VERSION, 43 ASSERT_ENUM_BOUNDS(SERVER_VERSION, TRANSACTION_VERSION, BASE_VERSION + 1,
48 BASE_VERSION + 1, INT64_FIELDS_END - 1); 44 INT64_FIELDS_END - 1);
49 switch (int64_field) { 45 switch (int64_field) {
50 ENUM_CASE(SERVER_VERSION); 46 ENUM_CASE(SERVER_VERSION);
51 ENUM_CASE(LOCAL_EXTERNAL_ID); 47 ENUM_CASE(LOCAL_EXTERNAL_ID);
52 ENUM_CASE(TRANSACTION_VERSION); 48 ENUM_CASE(TRANSACTION_VERSION);
53 case INT64_FIELDS_END: break; 49 case INT64_FIELDS_END:
50 break;
54 } 51 }
55 NOTREACHED(); 52 NOTREACHED();
56 return ""; 53 return "";
57 } 54 }
58 55
59 const char* GetTimeFieldString(TimeField time_field) { 56 const char* GetTimeFieldString(TimeField time_field) {
60 ASSERT_ENUM_BOUNDS(MTIME, SERVER_CTIME, 57 ASSERT_ENUM_BOUNDS(MTIME, SERVER_CTIME, TIME_FIELDS_BEGIN,
61 TIME_FIELDS_BEGIN, TIME_FIELDS_END - 1); 58 TIME_FIELDS_END - 1);
62 switch (time_field) { 59 switch (time_field) {
63 ENUM_CASE(MTIME); 60 ENUM_CASE(MTIME);
64 ENUM_CASE(SERVER_MTIME); 61 ENUM_CASE(SERVER_MTIME);
65 ENUM_CASE(CTIME); 62 ENUM_CASE(CTIME);
66 ENUM_CASE(SERVER_CTIME); 63 ENUM_CASE(SERVER_CTIME);
67 case TIME_FIELDS_END: break; 64 case TIME_FIELDS_END:
65 break;
68 } 66 }
69 NOTREACHED(); 67 NOTREACHED();
70 return ""; 68 return "";
71 } 69 }
72 70
73 const char* GetIdFieldString(IdField id_field) { 71 const char* GetIdFieldString(IdField id_field) {
74 ASSERT_ENUM_BOUNDS(ID, SERVER_PARENT_ID, 72 ASSERT_ENUM_BOUNDS(ID, SERVER_PARENT_ID, ID_FIELDS_BEGIN, ID_FIELDS_END - 1);
75 ID_FIELDS_BEGIN, ID_FIELDS_END - 1);
76 switch (id_field) { 73 switch (id_field) {
77 ENUM_CASE(ID); 74 ENUM_CASE(ID);
78 ENUM_CASE(PARENT_ID); 75 ENUM_CASE(PARENT_ID);
79 ENUM_CASE(SERVER_PARENT_ID); 76 ENUM_CASE(SERVER_PARENT_ID);
80 case ID_FIELDS_END: break; 77 case ID_FIELDS_END:
78 break;
81 } 79 }
82 NOTREACHED(); 80 NOTREACHED();
83 return ""; 81 return "";
84 } 82 }
85 83
86 const char* GetIndexedBitFieldString(IndexedBitField indexed_bit_field) { 84 const char* GetIndexedBitFieldString(IndexedBitField indexed_bit_field) {
87 ASSERT_ENUM_BOUNDS(IS_UNSYNCED, IS_UNAPPLIED_UPDATE, 85 ASSERT_ENUM_BOUNDS(IS_UNSYNCED, IS_UNAPPLIED_UPDATE, BIT_FIELDS_BEGIN,
88 BIT_FIELDS_BEGIN, INDEXED_BIT_FIELDS_END - 1); 86 INDEXED_BIT_FIELDS_END - 1);
89 switch (indexed_bit_field) { 87 switch (indexed_bit_field) {
90 ENUM_CASE(IS_UNSYNCED); 88 ENUM_CASE(IS_UNSYNCED);
91 ENUM_CASE(IS_UNAPPLIED_UPDATE); 89 ENUM_CASE(IS_UNAPPLIED_UPDATE);
92 case INDEXED_BIT_FIELDS_END: break; 90 case INDEXED_BIT_FIELDS_END:
91 break;
93 } 92 }
94 NOTREACHED(); 93 NOTREACHED();
95 return ""; 94 return "";
96 } 95 }
97 96
98 const char* GetIsDelFieldString(IsDelField is_del_field) { 97 const char* GetIsDelFieldString(IsDelField is_del_field) {
99 ASSERT_ENUM_BOUNDS(IS_DEL, IS_DEL, 98 ASSERT_ENUM_BOUNDS(IS_DEL, IS_DEL, INDEXED_BIT_FIELDS_END, IS_DIR - 1);
100 INDEXED_BIT_FIELDS_END, IS_DIR - 1); 99 switch (is_del_field) { ENUM_CASE(IS_DEL); }
101 switch (is_del_field) {
102 ENUM_CASE(IS_DEL);
103 }
104 NOTREACHED(); 100 NOTREACHED();
105 return ""; 101 return "";
106 } 102 }
107 103
108 const char* GetBitFieldString(BitField bit_field) { 104 const char* GetBitFieldString(BitField bit_field) {
109 ASSERT_ENUM_BOUNDS(IS_DIR, SERVER_IS_DEL, 105 ASSERT_ENUM_BOUNDS(IS_DIR, SERVER_IS_DEL, IS_DEL + 1, BIT_FIELDS_END - 1);
110 IS_DEL + 1, BIT_FIELDS_END - 1);
111 switch (bit_field) { 106 switch (bit_field) {
112 ENUM_CASE(IS_DIR); 107 ENUM_CASE(IS_DIR);
113 ENUM_CASE(SERVER_IS_DIR); 108 ENUM_CASE(SERVER_IS_DIR);
114 ENUM_CASE(SERVER_IS_DEL); 109 ENUM_CASE(SERVER_IS_DEL);
115 case BIT_FIELDS_END: break; 110 case BIT_FIELDS_END:
111 break;
116 } 112 }
117 NOTREACHED(); 113 NOTREACHED();
118 return ""; 114 return "";
119 } 115 }
120 116
121 const char* GetStringFieldString(StringField string_field) { 117 const char* GetStringFieldString(StringField string_field) {
122 ASSERT_ENUM_BOUNDS(NON_UNIQUE_NAME, UNIQUE_BOOKMARK_TAG, 118 ASSERT_ENUM_BOUNDS(NON_UNIQUE_NAME, UNIQUE_BOOKMARK_TAG, STRING_FIELDS_BEGIN,
123 STRING_FIELDS_BEGIN, STRING_FIELDS_END - 1); 119 STRING_FIELDS_END - 1);
124 switch (string_field) { 120 switch (string_field) {
125 ENUM_CASE(NON_UNIQUE_NAME); 121 ENUM_CASE(NON_UNIQUE_NAME);
126 ENUM_CASE(SERVER_NON_UNIQUE_NAME); 122 ENUM_CASE(SERVER_NON_UNIQUE_NAME);
127 ENUM_CASE(UNIQUE_SERVER_TAG); 123 ENUM_CASE(UNIQUE_SERVER_TAG);
128 ENUM_CASE(UNIQUE_CLIENT_TAG); 124 ENUM_CASE(UNIQUE_CLIENT_TAG);
129 ENUM_CASE(UNIQUE_BOOKMARK_TAG); 125 ENUM_CASE(UNIQUE_BOOKMARK_TAG);
130 case STRING_FIELDS_END: break; 126 case STRING_FIELDS_END:
127 break;
131 } 128 }
132 NOTREACHED(); 129 NOTREACHED();
133 return ""; 130 return "";
134 } 131 }
135 132
136 const char* GetProtoFieldString(ProtoField proto_field) { 133 const char* GetProtoFieldString(ProtoField proto_field) {
137 ASSERT_ENUM_BOUNDS(SPECIFICS, BASE_SERVER_SPECIFICS, 134 ASSERT_ENUM_BOUNDS(SPECIFICS, BASE_SERVER_SPECIFICS, PROTO_FIELDS_BEGIN,
138 PROTO_FIELDS_BEGIN, PROTO_FIELDS_END - 1); 135 PROTO_FIELDS_END - 1);
139 switch (proto_field) { 136 switch (proto_field) {
140 ENUM_CASE(SPECIFICS); 137 ENUM_CASE(SPECIFICS);
141 ENUM_CASE(SERVER_SPECIFICS); 138 ENUM_CASE(SERVER_SPECIFICS);
142 ENUM_CASE(BASE_SERVER_SPECIFICS); 139 ENUM_CASE(BASE_SERVER_SPECIFICS);
143 case PROTO_FIELDS_END: break; 140 case PROTO_FIELDS_END:
141 break;
144 } 142 }
145 NOTREACHED(); 143 NOTREACHED();
146 return ""; 144 return "";
147 } 145 }
148 146
149 const char* GetUniquePositionFieldString(UniquePositionField position_field) { 147 const char* GetUniquePositionFieldString(UniquePositionField position_field) {
150 ASSERT_ENUM_BOUNDS(SERVER_UNIQUE_POSITION, UNIQUE_POSITION, 148 ASSERT_ENUM_BOUNDS(SERVER_UNIQUE_POSITION, UNIQUE_POSITION,
151 UNIQUE_POSITION_FIELDS_BEGIN, 149 UNIQUE_POSITION_FIELDS_BEGIN,
152 UNIQUE_POSITION_FIELDS_END - 1); 150 UNIQUE_POSITION_FIELDS_END - 1);
153 switch (position_field) { 151 switch (position_field) {
154 ENUM_CASE(SERVER_UNIQUE_POSITION); 152 ENUM_CASE(SERVER_UNIQUE_POSITION);
155 ENUM_CASE(UNIQUE_POSITION); 153 ENUM_CASE(UNIQUE_POSITION);
156 case UNIQUE_POSITION_FIELDS_END: break; 154 case UNIQUE_POSITION_FIELDS_END:
155 break;
157 } 156 }
158 NOTREACHED(); 157 NOTREACHED();
159 return ""; 158 return "";
160 } 159 }
161 160
162 const char* GetAttachmentMetadataFieldString( 161 const char* GetAttachmentMetadataFieldString(
163 AttachmentMetadataField attachment_metadata_field) { 162 AttachmentMetadataField attachment_metadata_field) {
164 ASSERT_ENUM_BOUNDS(ATTACHMENT_METADATA, 163 ASSERT_ENUM_BOUNDS(ATTACHMENT_METADATA, SERVER_ATTACHMENT_METADATA,
165 SERVER_ATTACHMENT_METADATA,
166 ATTACHMENT_METADATA_FIELDS_BEGIN, 164 ATTACHMENT_METADATA_FIELDS_BEGIN,
167 ATTACHMENT_METADATA_FIELDS_END - 1); 165 ATTACHMENT_METADATA_FIELDS_END - 1);
168 switch (attachment_metadata_field) { 166 switch (attachment_metadata_field) {
169 ENUM_CASE(ATTACHMENT_METADATA); 167 ENUM_CASE(ATTACHMENT_METADATA);
170 ENUM_CASE(SERVER_ATTACHMENT_METADATA); 168 ENUM_CASE(SERVER_ATTACHMENT_METADATA);
171 case ATTACHMENT_METADATA_FIELDS_END: break; 169 case ATTACHMENT_METADATA_FIELDS_END:
170 break;
172 } 171 }
173 NOTREACHED(); 172 NOTREACHED();
174 return ""; 173 return "";
175 } 174 }
176 175
177 const char* GetBitTempString(BitTemp bit_temp) { 176 const char* GetBitTempString(BitTemp bit_temp) {
178 ASSERT_ENUM_BOUNDS(SYNCING, DIRTY_SYNC, 177 ASSERT_ENUM_BOUNDS(SYNCING, DIRTY_SYNC, BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1);
179 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1);
180 switch (bit_temp) { 178 switch (bit_temp) {
181 ENUM_CASE(SYNCING); 179 ENUM_CASE(SYNCING);
182 ENUM_CASE(DIRTY_SYNC); 180 ENUM_CASE(DIRTY_SYNC);
183 case BIT_TEMPS_END: break; 181 case BIT_TEMPS_END:
182 break;
184 } 183 }
185 NOTREACHED(); 184 NOTREACHED();
186 return ""; 185 return "";
187 } 186 }
188 187
189 #undef ENUM_CASE 188 #undef ENUM_CASE
190 #undef ASSERT_ENUM_BOUNDS 189 #undef ASSERT_ENUM_BOUNDS
191 190
192 } // namespace syncable 191 } // namespace syncable
193 } // namespace syncer 192 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/syncable_enum_conversions.h ('k') | components/sync/syncable/syncable_enum_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698