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)
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
46 #ifndef LIB_SUB_ID_H
47 #define LIB_SUB_ID_H
48 
49 #include "lib/format-util.hpp"
50 
51 //#include <functional>
52 #include <boost/functional/hash.hpp>
53 
54 #include <string>
55 
56 
57 namespace lib {
58 
59  using boost::hash_value;
60  using std::string;
61 
62 
63 
67  template<typename I>
68  class SubId;
69 
70  class SubID
71  {
72  public:
73  virtual ~SubID() { }
74 
75  virtual operator string() const =0;
76  };
77 
78 
79  inline size_t
80  hash_value (SubID const& sID)
81  {
82  return hash_value (string (sID));
83  }
84 
85  inline bool
86  operator== (SubID const& id1, SubID const& id2)
87  {
88  return (string (id1) == string (id2));
89  }
90 
92 
93 
94 
95 
96 
97 
98  template<typename I>
99  class SubId
100  : public SubID
101  {
102  I baseID_;
103 
104  public:
105  SubId (I id)
106  : baseID_(id)
107  { }
108 
109  operator string() const
110  {
111  using util::toString;
112  return toString (baseID_); // note: extension point
113  }
114  };
115 
116 
117  template<typename I, class SUZ>
119  : public SubId<I>
120  {
121  typedef SubId<I> _baID;
122 
123  SUZ extID_;
124 
125  public:
126  ExtendedSubId (I i, SUZ const& chain)
127  : _baID(i)
128  , extID_(chain)
129  { }
130 
131  operator string() const
132  {
133  return _baID::operator string()
134  + '.'
135  + string (extID_);
136  }
137  };
138 
139 
140 
141 
142 } // namespace lib
143 #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:52
Collection of small helpers and convenience shortcuts for diagnostics & formatting.