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

Side by Side Diff: src/common/chromeos/glib/object.h

Issue 603052: Add int32 converstion to G_TYPE_INT (Closed)
Patch Set: Created 10 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 #ifndef CHROMEOS_GLIB_OBJECT_H_ 5 #ifndef CHROMEOS_GLIB_OBJECT_H_
6 #define CHROMEOS_GLIB_OBJECT_H_ 6 #define CHROMEOS_GLIB_OBJECT_H_
7 7
8 #include <glib-object.h> 8 #include <glib-object.h>
9 9
10 #include <base/basictypes.h> 10 #include <base/basictypes.h>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // assumes sizeof(guint) == sizeof(guint32). Need a static_assert to assert 108 // assumes sizeof(guint) == sizeof(guint32). Need a static_assert to assert
109 // that. 109 // that.
110 return G_TYPE_UINT; 110 return G_TYPE_UINT;
111 }; 111 };
112 112
113 template < > 113 template < >
114 inline ::GType type_to_gtypeid< ::int64>() { 114 inline ::GType type_to_gtypeid< ::int64>() {
115 return G_TYPE_INT64; 115 return G_TYPE_INT64;
116 }; 116 };
117 117
118 template < >
119 inline ::GType type_to_gtypeid< ::int32>() {
120 return G_TYPE_INT;
121 };
122
118 // \brief Value (and Retrieve) support using std::string as well as const char* 123 // \brief Value (and Retrieve) support using std::string as well as const char*
119 // by promoting from const char* to the string. promote_from provides a mapping 124 // by promoting from const char* to the string. promote_from provides a mapping
120 // for this promotion (and possibly others in the future). 125 // for this promotion (and possibly others in the future).
121 126
122 template <typename T> struct promotes_from { 127 template <typename T> struct promotes_from {
123 typedef T type; 128 typedef T type;
124 }; 129 };
125 template < > struct promotes_from<std::string> { 130 template < > struct promotes_from<std::string> {
126 typedef const char* type; 131 typedef const char* type;
127 }; 132 };
(...skipping 23 matching lines...) Expand all
151 return static_cast<bool>(::g_value_get_boolean(&x)); 156 return static_cast<bool>(::g_value_get_boolean(&x));
152 } 157 }
153 template < > 158 template < >
154 inline ::uint32 RawCast< ::uint32>(const ::GValue& x) { 159 inline ::uint32 RawCast< ::uint32>(const ::GValue& x) {
155 return static_cast< ::uint32>(::g_value_get_uint(&x)); 160 return static_cast< ::uint32>(::g_value_get_uint(&x));
156 } 161 }
157 template < > 162 template < >
158 inline ::uint8 RawCast< ::uint8>(const ::GValue& x) { 163 inline ::uint8 RawCast< ::uint8>(const ::GValue& x) {
159 return static_cast< ::uint8>(::g_value_get_uchar(&x)); 164 return static_cast< ::uint8>(::g_value_get_uchar(&x));
160 } 165 }
161
162 template < > 166 template < >
163 inline ::int64 RawCast< ::int64>(const ::GValue& x) { 167 inline ::int64 RawCast< ::int64>(const ::GValue& x) {
164 return static_cast< ::int64>(::g_value_get_int64(&x)); 168 return static_cast< ::int64>(::g_value_get_int64(&x));
165 } 169 }
170 template < >
171 inline ::int32 RawCast< ::int32>(const ::GValue& x) {
172 return static_cast< ::int32>(::g_value_get_int(&x));
173 }
166 174
167 inline void RawSet(GValue* x, const std::string& v) { 175 inline void RawSet(GValue* x, const std::string& v) {
168 ::g_value_set_string(x, v.c_str()); 176 ::g_value_set_string(x, v.c_str());
169 } 177 }
170 inline void RawSet(GValue* x, const char* v) { 178 inline void RawSet(GValue* x, const char* v) {
171 ::g_value_set_string(x, v); 179 ::g_value_set_string(x, v);
172 } 180 }
173 inline void RawSet(GValue* x, double v) { 181 inline void RawSet(GValue* x, double v) {
174 ::g_value_set_double(x, v); 182 ::g_value_set_double(x, v);
175 } 183 }
176 inline void RawSet(GValue* x, bool v) { 184 inline void RawSet(GValue* x, bool v) {
177 ::g_value_set_boolean(x, v); 185 ::g_value_set_boolean(x, v);
178 } 186 }
179 inline void RawSet(GValue* x, ::uint32 v) { 187 inline void RawSet(GValue* x, ::uint32 v) {
180 ::g_value_set_uint(x, v); 188 ::g_value_set_uint(x, v);
181 } 189 }
182 inline void RawSet(GValue* x, ::uint8 v) { 190 inline void RawSet(GValue* x, ::uint8 v) {
183 ::g_value_set_uchar(x, v); 191 ::g_value_set_uchar(x, v);
184 } 192 }
185 inline void RawSet(GValue* x, ::int64 v) { 193 inline void RawSet(GValue* x, ::int64 v) {
186 ::g_value_set_int64(x, v); 194 ::g_value_set_int64(x, v);
187 } 195 }
196 inline void RawSet(GValue* x, ::int32 v) {
197 ::g_value_set_int(x, v);
198 }
188 199
189 // \brief Value is a data type for managing GValues. 200 // \brief Value is a data type for managing GValues.
190 // 201 //
191 // A Value is a polymorphic container holding at most a single value. 202 // A Value is a polymorphic container holding at most a single value.
192 // 203 //
193 // The Value wrapper ensures proper initialization, copies, and assignment of 204 // The Value wrapper ensures proper initialization, copies, and assignment of
194 // GValues. 205 // GValues.
195 // 206 //
196 // \note GValues are equationally incomplete and so can't support proper 207 // \note GValues are equationally incomplete and so can't support proper
197 // equality. The semantics of copy are verified with equality of retrieved 208 // equality. The semantics of copy are verified with equality of retrieved
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 479 }
469 480
470 private: 481 private:
471 ::GHashTable* object_; 482 ::GHashTable* object_;
472 }; 483 };
473 484
474 } // namespace glib 485 } // namespace glib
475 } // namespace chromeos 486 } // namespace chromeos
476 487
477 #endif // GLIB_OBJECT_H_ 488 #endif // GLIB_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698