00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _OSBID_H_
00031 #define _OSBID_H_
00032
00033
00034
00035
00036 #include<iosfwd>
00037 #include<functional>
00038
00039
00040
00041
00042 #include "osbconst.h"
00043
00044
00045
00046 namespace OSB_LIB {
00047
00048
00049
00086 template<typename T> struct Id {
00087 public:
00091 explicit Id(long id = ID_NOT_SET) : id_(id) {}
00093 long id() const { return id_; }
00095 bool notSet() const { return ID_NOT_SET == id_; }
00097 bool isSet() const { return !notSet(); }
00102 bool operator==(const Id& rhs) const { return id_ == rhs.id_; }
00103 bool operator!=(const Id& rhs) const { return id_ != rhs.id_; }
00104 bool operator< (const Id& rhs) const { return id_ < rhs.id_; }
00105 bool operator> (const Id& rhs) const { return id_ > rhs.id_; }
00106 bool operator<=(const Id& rhs) const { return id_ <= rhs.id_; }
00107 bool operator>=(const Id& rhs) const { return id_ >= rhs.id_; }
00109 private:
00111 long id_;
00112 };
00113
00115 template<typename T>
00116 std::ostream& operator<<(std::ostream& o, Id<T> id)
00117 {
00118 return o << id.id();
00119 }
00120
00135 template<typename I> struct Id2 {
00137 Id2() : id1_(ID_NOT_SET), id2_(ID_NOT_SET) {}
00139 explicit Id2(long id1) : id1_(id1), id2_(ID_NOT_SET) {}
00141 Id2(long id1, long id2) : id1_(id1), id2_(id2) {}
00142
00148 bool isSet() const
00149 {
00150 return ID_NOT_SET != id1_ || ID_NOT_SET != id2_;
00151 }
00157 bool notSet() const { return !isSet(); }
00159 bool id1Set() const { return ID_NOT_SET != id1_; }
00161 bool id2Set() const { return ID_NOT_SET != id2_; }
00162
00168 bool operator==(const Id2& rhs) const
00169 {
00170 return id1_ == rhs.id1_ && id2_ == rhs.id2_;
00171 }
00172
00173 bool operator!=(const Id2& rhs) const
00174 {
00175 return !(*this == rhs);
00176 }
00177
00178 bool operator<(const Id2& rhs) const
00179 {
00180 return id1_ == rhs.id1_ ?
00181 id2_ < rhs.id2_ :
00182 id1_ < rhs.id1_;
00183 }
00184
00185 bool operator>(const Id2& rhs) const
00186 {
00187 return rhs < *this;
00188 }
00189
00190 bool operator<=(const Id2& rhs) const
00191 {
00192 return !(rhs < *this);
00193 }
00194
00195 bool operator>=(const Id2& rhs) const
00196 {
00197 return !(*this < rhs);
00198 }
00200
00201 public:
00203 long id1_;
00205 long id2_;
00206 };
00207
00209 template<typename I>
00210 std::ostream& operator<<(std::ostream& o, Id2<I> id)
00211 {
00212 return o << id.id1_ << '.' << id.id2_;
00213 }
00214
00221 template < class T, class Oid =Id<T> >
00222 class MatchOid : public std::unary_function <T, bool> {
00223 Oid oid_;
00224 public:
00225 explicit MatchOid(const Oid& oid) : oid_(oid) {}
00226 bool operator() (const T& t) const { return t.oid() == oid_; }
00227 };
00228
00235 template<class T, class Oid>
00236 class MatchOid<T*, Oid> : public std::unary_function<T*, bool> {
00237 Oid oid_;
00238 public:
00239 explicit MatchOid(const Oid& oid) : oid_(oid) {}
00240 bool operator() (const T* t) const { return t->oid() == oid_; }
00241 };
00242 }
00243 #endif // #ifndef _OSBID_H_