stlab.adobe.com Adobe Systems Incorporated
name.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_NAME_HPP
10 #define ADOBE_NAME_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <adobe/name_fwd.hpp>
15 
16 #include <boost/utility.hpp>
17 
18 #include <adobe/conversion.hpp>
19 #include <adobe/cstring.hpp>
20 #include <adobe/typeinfo.hpp>
21 
22 /*************************************************************************************************/
23 
24 namespace adobe {
25 
26 /*************************************************************************************************/
27 
28 namespace version_1 {
29 
34 /*************************************************************************************************/
35 
36 #if !defined(ADOBE_NO_DOCUMENTATION)
37 
38 inline name_t::operator bool() const { return *name_m != 0; }
39 
40 inline bool name_t::operator!() const { return !(*name_m); }
41 
42 #endif
43 
44 /*************************************************************************************************/
45 
46 inline bool operator<(const name_t& x, const name_t& y)
47 {
48  return adobe::strcmp(x.c_str(), y.c_str()) < 0;
49 }
50 
51 inline bool operator == (const name_t& x, const name_t& y)
52 {
53  /*
54  The test case for equal strings is "optimized" because names are stored in hash tables and
55  will often match on a find because the compiler will pool string constants.
56  */
57  if (x.c_str() == y.c_str()) return true;
58  return adobe::strcmp(x.c_str(), y.c_str()) == 0;
59 }
60 
61 /*************************************************************************************************/
62 
63 inline const char* name_t::c_str() const
64 {
65  return name_m;
66 }
67 
68 /*************************************************************************************************/
69 
70 class static_name_t : public name_t
71 {
72  public:
73  explicit static_name_t (const char* string_name = "") :
74  name_t(string_name, dont_copy_t()) { }
75 };
76 
78 {
79  const char* const name_m;
80  operator name_t() const { return name_t(name_m, name_t::dont_copy_t()); }
81 };
82 
83 /*
84  NOTE (sparent) : This is to allow for boost::hash<> to work with name_t. boost::hash<> relies
85  on argument dependent lookup.
86 */
87 
88 inline std::size_t hash_value(name_t name)
89 {
90  std::size_t seed = 0;
91  for (const char* first = name.c_str(); *first; ++first) {
92  seed = 5 * seed + *first;
93  }
94  return seed;
95 }
96 
98 
99 /*************************************************************************************************/
100 
101 } // namespace version_1
102 
103 /*************************************************************************************************/
104 
105 template <> struct promote<static_name_t> { typedef name_t type; };
106 template <> struct promote<aggregate_name_t> { typedef name_t type; };
107 
108 /*************************************************************************************************/
109 
110 } // namespace adobe
111 
112 /*************************************************************************************************/
113 
114 ADOBE_NAME_TYPE_0("name_t:version_1:adobe", adobe::version_1::name_t)
116 
117 #endif
118 
119 /*************************************************************************************************/
int strcmp(const char *x, const char *y)
Definition: cstring.hpp:22
name_t(const char *string_name="")
A struct for compile-time type promotion.
Definition: conversion.hpp:24
std::size_t hash_value(name_t name)
Definition: name.hpp:88
bool operator<(const name_t &x, const name_t &y)
Definition: name.hpp:46
const char *const name_m
Definition: name.hpp:79
static_name_t(const char *string_name="")
Definition: name.hpp:73
bool operator==(const function< F > &x, null_ptr_t)
Definition: function.hpp:168
#define ADOBE_SHORT_NAME_TYPE(a, b, c, d, T)
Definition: typeinfo.hpp:412
const char * c_str() const
Definition: name.hpp:63

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google