Lumiera  0.pre.03
»edit your freedom«
sub-id.hpp
Go to the documentation of this file.
1 /*
2  SUB-ID.hpp - extensible symbolic identifier
3 
4  Copyright (C) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
55 #ifndef LIB_SUB_ID_H
56 #define LIB_SUB_ID_H
57 
58 #include "lib/format-util.hpp"
59 
60 //#include <functional>
61 #include <boost/functional/hash.hpp>
62 
63 #include <string>
64 
65 
66 namespace lib {
67 
68  using boost::hash_value;
69  using std::string;
70 
71 
72 
76  template<typename I>
77  class SubId;
78 
79  class SubID
80  {
81  public:
82  virtual ~SubID() { }
83 
84  virtual operator string() const =0;
85  };
86 
87 
88  inline size_t
89  hash_value (SubID const& sID)
90  {
91  return hash_value (string (sID));
92  }
93 
94  inline bool
95  operator== (SubID const& id1, SubID const& id2)
96  {
97  return (string (id1) == string (id2));
98  }
99 
101 
102 
103 
104 
105 
106 
107  template<typename I>
108  class SubId
109  : public SubID
110  {
111  I baseID_;
112 
113  public:
114  SubId (I id)
115  : baseID_(id)
116  { }
117 
118  operator string() const
119  {
120  using util::toString;
121  return toString (baseID_); // note: extension point
122  }
123  };
124 
125 
126  template<typename I, class SUZ>
128  : public SubId<I>
129  {
130  typedef SubId<I> _baID;
131 
132  SUZ extID_;
133 
134  public:
135  ExtendedSubId (I i, SUZ const& chain)
136  : _baID(i)
137  , extID_(chain)
138  { }
139 
140  operator string() const
141  {
142  return _baID::operator string()
143  + '.'
144  + string (extID_);
145  }
146  };
147 
148 
149 
150 
151 } // namespace lib
152 #endif
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
Implementation namespace for support and library code.
HashVal hash_value(QueryText const &entry)
support using queries in hashtables.
Definition: query-text.cpp:61
Collection of small helpers and convenience shortcuts for diagnostics & formatting.