We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / sync / syncable / syncable_enum_conversions.cc
blobfe8cd5d436989cef945057ca34c5ff35ae448396
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"
12 namespace syncer {
13 namespace syncable {
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 static_assert(static_cast<int>(enum_min) == \
19 static_cast<int>(expected_min), \
20 #enum_min " not " #expected_min); \
21 static_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);
33 NOTREACHED();
34 return "";
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);
43 NOTREACHED();
44 return "";
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;
56 NOTREACHED();
57 return "";
60 const char* GetTimeFieldString(TimeField time_field) {
61 ASSERT_ENUM_BOUNDS(MTIME, SERVER_CTIME,
62 TIME_FIELDS_BEGIN, TIME_FIELDS_END - 1);
63 switch (time_field) {
64 ENUM_CASE(MTIME);
65 ENUM_CASE(SERVER_MTIME);
66 ENUM_CASE(CTIME);
67 ENUM_CASE(SERVER_CTIME);
68 case TIME_FIELDS_END: break;
70 NOTREACHED();
71 return "";
74 const char* GetIdFieldString(IdField id_field) {
75 ASSERT_ENUM_BOUNDS(ID, SERVER_PARENT_ID,
76 ID_FIELDS_BEGIN, ID_FIELDS_END - 1);
77 switch (id_field) {
78 ENUM_CASE(ID);
79 ENUM_CASE(PARENT_ID);
80 ENUM_CASE(SERVER_PARENT_ID);
81 case ID_FIELDS_END: break;
83 NOTREACHED();
84 return "";
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;
95 NOTREACHED();
96 return "";
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) {
103 ENUM_CASE(IS_DEL);
105 NOTREACHED();
106 return "";
109 const char* GetBitFieldString(BitField bit_field) {
110 ASSERT_ENUM_BOUNDS(IS_DIR, SERVER_IS_DEL,
111 IS_DEL + 1, BIT_FIELDS_END - 1);
112 switch (bit_field) {
113 ENUM_CASE(IS_DIR);
114 ENUM_CASE(SERVER_IS_DIR);
115 ENUM_CASE(SERVER_IS_DEL);
116 case BIT_FIELDS_END: break;
118 NOTREACHED();
119 return "";
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;
133 NOTREACHED();
134 return "";
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;
146 NOTREACHED();
147 return "";
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;
159 NOTREACHED();
160 return "";
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;
174 NOTREACHED();
175 return "";
178 const char* GetBitTempString(BitTemp bit_temp) {
179 ASSERT_ENUM_BOUNDS(SYNCING, DIRTY_SYNC,
180 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1);
181 switch (bit_temp) {
182 ENUM_CASE(SYNCING);
183 ENUM_CASE(DIRTY_SYNC);
184 case BIT_TEMPS_END: break;
186 NOTREACHED();
187 return "";
190 #undef ENUM_CASE
191 #undef ASSERT_ENUM_BOUNDS
193 } // namespace syncable
194 } // namespace syncer