basic_symbol.hh
Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * $Id: basic_symbol.hh 961 2005-03-11 14:05:33Z fpy $
00003  */
00004 #ifndef UTILMM_TYPES_BASIC_SYMBOL_HEADER
00005 # define UTILMM_TYPES_BASIC_SYMBOL_HEADER
00006 
00007 #include "utilmm/smart/uniq_pointer.hh"
00008 #include "utilmm/hash/hash.hh"
00009 
00010 #include "utilmm/types/bits/basic_symbol_fwd.hh"
00011 
00012 namespace utilmm {
00013   
00025   template<class CharT, class Traits, class Alloc>
00026   class basic_symbol {
00027   public:
00029     typedef std::basic_string<CharT, Traits, Alloc> str_type;
00030     
00031   private:
00032     typedef typename smart::uniq_pointer<str_type>::type ref_type;
00033 
00034   public:
00041     basic_symbol(str_type const &str = str_type())
00042       :name(create(str)) {}
00049     basic_symbol(CharT const *str)
00050       :name(create(str_type(str))) {}
00052     basic_symbol(basic_symbol const &other)
00053       :name(other.name) {}
00054 
00056     ~basic_symbol() {}
00057 
00059     basic_symbol &operator= (basic_symbol const &other) {
00060       name = other.name;
00061       return *this;
00062     }
00063 
00071     bool empty() const {
00072       return name.null();
00073     }
00078     size_t length() const {
00079       return size_t(empty()?0:name->size());
00080     }
00081 
00092     bool operator==(basic_symbol const &other) const {
00093       return name==other.name;
00094     }
00101     bool operator!=(basic_symbol const &other) const {
00102       return !operator==(other);
00103     }
00104 
00106     bool operator< (basic_symbol const &other) const;
00108     bool operator> (basic_symbol const &other) const {
00109       return other.operator< (*this);
00110     }
00112     bool operator<=(basic_symbol const &other) const {
00113       return !operator> (other);
00114     }
00116     bool operator>=(basic_symbol const &other) const {
00117       return !operator< (other);
00118     }
00119 
00128     bool starts_with(basic_symbol const &sub) const;
00129 
00142     basic_symbol &append(basic_symbol const &other);
00147     basic_symbol &operator+=(basic_symbol const &other) {
00148       return append(other);
00149     }
00150 
00159     basic_symbol operator+ (basic_symbol const &other) const;
00160 
00168     str_type const &str() const {
00169       return *name;
00170     }
00171 
00172   private:
00173     ref_type name;
00174 
00175     static ref_type create(str_type const &str);
00176 
00177     template<typename Ty>
00178     friend struct hash;
00179   }; // class utilmm::basic_symbol<>
00180 
00181   template<class CharT, class Traits, class Alloc>
00182   struct hash< basic_symbol<CharT, Traits, Alloc> >
00183     :public std::unary_function< basic_symbol<CharT, Traits, Alloc>,
00184                                  size_t > {
00185     size_t operator()(basic_symbol<CharT, Traits, Alloc> const &x) const;
00186   }; // struct utilmm::hash< utilmm::basic_symbol<> >
00187   
00188 } // namespace utilmm
00189 
00190 # define IN_UTILMM_TYPES_BASIC_SYMBOL_HEADER
00191 #include "utilmm/types/bits/basic_symbol.tcc"
00192 # undef IN_UTILMM_TYPES_BASIC_SYMBOL_HEADER
00193 #endif // UTILMM_TYPES_BASIC_SYMBOL_HEADER
00194 


utilmm
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Mon Oct 6 2014 03:17:01