Util--  1.1
basic_symbol.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * $Id: basic_symbol.hh 961 2005-03-11 14:05:33Z fpy $
3  */
4 #ifndef UTILMM_TYPES_BASIC_SYMBOL_HEADER
5 # define UTILMM_TYPES_BASIC_SYMBOL_HEADER
6 
8 #include "utilmm/hash/hash.hh"
9 
11 
12 namespace utilmm {
13 
25  template<class CharT, class Traits, class Alloc>
26  class basic_symbol {
27  public:
29  typedef std::basic_string<CharT, Traits, Alloc> str_type;
30 
31  private:
33 
34  public:
41  basic_symbol(str_type const &str = str_type())
42  :name(create(str)) {}
49  basic_symbol(CharT const *str)
50  :name(create(str_type(str))) {}
52  basic_symbol(basic_symbol const &other)
53  :name(other.name) {}
54 
57 
60  name = other.name;
61  return *this;
62  }
63 
71  bool empty() const {
72  return name.null();
73  }
78  size_t length() const {
79  return size_t(empty()?0:name->size());
80  }
81 
92  bool operator==(basic_symbol const &other) const {
93  return name==other.name;
94  }
101  bool operator!=(basic_symbol const &other) const {
102  return !operator==(other);
103  }
104 
106  bool operator< (basic_symbol const &other) const;
108  bool operator> (basic_symbol const &other) const {
109  return other.operator< (*this);
110  }
112  bool operator<=(basic_symbol const &other) const {
113  return !operator> (other);
114  }
116  bool operator>=(basic_symbol const &other) const {
117  return !operator< (other);
118  }
119 
128  bool starts_with(basic_symbol const &sub) const;
129 
142  basic_symbol &append(basic_symbol const &other);
148  return append(other);
149  }
150 
159  basic_symbol operator+ (basic_symbol const &other) const;
160 
168  str_type const &str() const {
169  return *name;
170  }
171 
172  private:
173  ref_type name;
174 
175  static ref_type create(str_type const &str);
176 
177  template<typename Ty>
178  friend struct hash;
179  }; // class utilmm::basic_symbol<>
180 
181  template<class CharT, class Traits, class Alloc>
182  struct hash< basic_symbol<CharT, Traits, Alloc> >
183  :public std::unary_function< basic_symbol<CharT, Traits, Alloc>,
184  size_t > {
185  size_t operator()(basic_symbol<CharT, Traits, Alloc> const &x) const;
186  }; // struct utilmm::hash< utilmm::basic_symbol<> >
187 
188 } // namespace utilmm
189 
190 # define IN_UTILMM_TYPES_BASIC_SYMBOL_HEADER
191 #include "utilmm/types/bits/basic_symbol.tcc"
192 # undef IN_UTILMM_TYPES_BASIC_SYMBOL_HEADER
193 #endif // UTILMM_TYPES_BASIC_SYMBOL_HEADER
194 
hash functor
Definition: hash.hh:30
str_type const & str() const
Name of the symbol.
Definition: basic_symbol.hh:168
basic_symbol & operator=(basic_symbol const &other)
Assignment operator.
Definition: basic_symbol.hh:59
basic_symbol & operator+=(basic_symbol const &other)
Append operator.
Definition: basic_symbol.hh:147
bool operator<(basic_symbol const &other) const
Ordering operator.
~basic_symbol()
Destructor.
Definition: basic_symbol.hh:56
basic_symbol operator+(basic_symbol const &other) const
Append operation.
Definition of a reference counting smart pointer.
std::basic_string< CharT, Traits, Alloc > str_type
equivalent string type
Definition: basic_symbol.hh:29
bool null() const
Check if null.
Generic smart pointer.
Definition: pointer.hh:52
Generic string using unique instance memory.
Definition: basic_symbol.hh:26
Definition: auto_flag.hh:6
bool starts_with(basic_symbol const &sub) const
Check for beginning.
basic_symbol(CharT const *str)
Constructor.
Definition: basic_symbol.hh:49
basic_symbol & append(basic_symbol const &other)
Append function.
size_t length() const
length of symbol
Definition: basic_symbol.hh:78
Forward declaration of utilmm::basic_symbol.
basic_symbol(str_type const &str=str_type())
Constructor.
Definition: basic_symbol.hh:41
bool operator>=(basic_symbol const &other) const
Ordering operator.
Definition: basic_symbol.hh:116
bool operator!=(basic_symbol const &other) const
Difference test.
Definition: basic_symbol.hh:101
bool empty() const
Check if empty.
Definition: basic_symbol.hh:71
definition of the basic hashing functor
bool operator==(basic_symbol const &other) const
Equality test.
Definition: basic_symbol.hh:92
basic_symbol(basic_symbol const &other)
Copy constructor.
Definition: basic_symbol.hh:52
bool operator>(basic_symbol const &other) const
Ordering operator.
Definition: basic_symbol.hh:108
bool operator<=(basic_symbol const &other) const
Ordering operator.
Definition: basic_symbol.hh:112

Generated on Wed Oct 17 2018 09:34:19 for Util-- by doxygen 1.8.13
SourceForge.net Project Page