stlab.adobe.com Adobe Systems Incorporated

name.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_NAME_HPP
00010 #define ADOBE_NAME_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <adobe/name_fwd.hpp>
00015 
00016 #include <boost/utility.hpp>
00017 
00018 #include <adobe/conversion.hpp>
00019 #include <adobe/cstring.hpp>
00020 #include <adobe/typeinfo.hpp>
00021 
00022 /*************************************************************************************************/
00023 
00024 namespace adobe {
00025 
00026 /*************************************************************************************************/
00027 
00028 namespace version_1 {
00029 
00034 /*************************************************************************************************/
00035 
00036 #if !defined(ADOBE_NO_DOCUMENTATION)
00037 
00038 inline name_t::operator bool() const { return *name_m != 0; }
00039 
00040 inline bool name_t::operator!() const { return !(*name_m); }
00041 
00042 #endif
00043 
00044 /*************************************************************************************************/
00045 
00046 inline bool operator<(const name_t& x, const name_t& y)
00047 {
00048     return adobe::strcmp(x.c_str(), y.c_str()) < 0;
00049 }
00050 
00051 inline bool operator == (const name_t& x, const name_t& y)
00052 {
00053     /*
00054         The test case for equal strings is "optimized" because names are stored in hash tables and
00055         will often match on a find because the compiler will pool string constants.
00056     */
00057     if (x.c_str() == y.c_str()) return true;
00058     return adobe::strcmp(x.c_str(), y.c_str()) == 0;
00059 }
00060 
00061 /*************************************************************************************************/
00062 
00063 inline const char* name_t::c_str() const
00064 {
00065     return name_m;
00066 }
00067     
00068 /*************************************************************************************************/
00069 
00070 class static_name_t : public name_t
00071 {
00072  public:
00073     explicit static_name_t (const char* string_name = "") :
00074         name_t(string_name, dont_copy_t()) { }
00075 };
00076 
00077 struct aggregate_name_t
00078 {
00079     const char* const name_m;
00080     operator name_t() const { return name_t(name_m, name_t::dont_copy_t()); }
00081 };
00082 
00083 /*
00084     NOTE (sparent) : This is to allow for boost::hash<> to work with name_t. boost::hash<> relies
00085     on argument dependent lookup.
00086 */
00087 
00088 inline std::size_t hash_value(name_t name)
00089 {
00090     std::size_t seed = 0; 
00091     for (const char* first = name.c_str(); *first; ++first) {
00092         seed = 5 * seed + *first;
00093     }
00094     return seed;
00095 }
00096     
00098 
00099 /*************************************************************************************************/
00100 
00101 } // namespace version_1
00102     
00103 /*************************************************************************************************/
00104 
00105 template <> struct promote<static_name_t> { typedef name_t type; };
00106 template <> struct promote<aggregate_name_t> { typedef name_t type; };
00107     
00108 /*************************************************************************************************/
00109 
00110 } // namespace adobe
00111 
00112 /*************************************************************************************************/
00113 
00114 ADOBE_NAME_TYPE_0("name_t:version_1:adobe", adobe::version_1::name_t)
00115 ADOBE_SHORT_NAME_TYPE('n','a','m','e', adobe::version_1::name_t)
00116 
00117 #endif
00118 
00119 /*************************************************************************************************/

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