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
00031 #ifndef _OSBUTILS_H_
00032 #define _OSBUTILS_H_
00033
00034
00035
00036
00037 #include<algorithm>
00038 #include<functional>
00039 #include<iosfwd>
00040 #include<string>
00041 #include<utility>
00042
00043
00044 #include "chrono.h"
00045 #include "osbid.h"
00046
00047
00048
00049 namespace OSB_LIB {
00050
00051
00052
00053
00054
00055
00056
00067 class EditStatus {
00068 public:
00070 enum Status {
00072 esUnchanged = 0x00,
00074 esModified = 0x01,
00076 esCreated = 0x02,
00078 esDeleted = 0x04
00079 };
00080
00082 EditStatus(Status status = esUnchanged);
00083
00099 bool setRead() const;
00100
00116 bool setCreated();
00117
00132 bool setModified();
00133
00150 bool changesDiscarded();
00151
00160 bool setDeleted();
00161
00170 bool setUndeleted();
00171
00173 Status status() const;
00174
00175 private:
00177 Status toStatus(int value) const;
00178
00180 int status_;
00181 };
00182
00183
00184 template<typename I>
00185 struct IdDate{
00186 IdDate() : id(ID_NOT_SET) {}
00187 IdDate(long i, const Date& d) : id(i), dt(d) {}
00188 IdDate(long i, const std::string& d_str) : id(i), dt(d_str) {}
00189 bool notSet() const { return ID_NOT_SET == id; }
00190 bool isSet() const { return !notSet(); }
00191 bool operator==(const IdDate& rhs) const
00192 { return id == rhs.id && dt == rhs.dt; }
00193 bool operator<(const IdDate& rhs) const
00194 { return id == rhs.id ? dt < rhs.dt : id < rhs.id; }
00195
00196 long id;
00197 Date dt;
00198 };
00199
00200
00201
00202
00203
00204
00205
00206 template<typename I>
00207 struct IdPeriod {
00208 IdPeriod() : id(ID_NOT_SET) {}
00209 IdPeriod(long i, const Date& d) : id(i), from(d), to(d) {}
00210 IdPeriod(long i, const std::string& d_str)
00211 : id(i), from(d_str), to(d_str) {}
00212 IdPeriod(long i, const Date& f, const Date& t)
00213 : id(i), from(std::min(f, t)), to(std::max(f, t)) {}
00214 IdPeriod(long i, const std::string& f_str,
00215 const std::string& t_str)
00216 : id(i), from(std::min(Date(f_str), Date(t_str))),
00217 to(std::max(Date(f_str), Date(t_str))) {}
00218 inline bool notSet() const { return ID_NOT_SET == id; }
00219 bool isSet() const { return !notSet(); }
00220 inline bool operator==(const IdPeriod& rhs) const;
00221 inline bool operator!=(const IdPeriod& rhs) const;
00222 inline bool operator< (const IdPeriod& rhs) const;
00223 inline bool operator> (const IdPeriod& rhs) const;
00224
00225 inline bool operator<=(const IdPeriod& rhs) const;
00226 inline bool operator>=(const IdPeriod& rhs) const;
00227
00228 long id;
00229 Date from;
00230 Date to;
00231 };
00232
00233
00234 template<typename I>
00235 std::ostream& operator<<(std::ostream& o, IdPeriod<I> Id)
00236 {
00237 return o << Id.id << ','
00238 << Id.from.str() << ','
00239 << Id.to.str();
00240 }
00241
00242
00243
00244 template<class T>
00245 struct LessOid : public std::binary_function<T, T, bool> {
00246 bool operator() (const T& x, const T& y) const
00247 { return x.oid() < y.oid(); }
00248 };
00249
00250
00251 template<class T>
00252 struct LessOid<T*> : public std::binary_function<T*, T*, bool> {
00253 bool operator() (const T* x, const T* y) const
00254 { return x->oid() < y->oid(); }
00255 };
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 template<typename I>
00266 inline bool IdPeriod<I>::operator==(const IdPeriod& rhs) const
00267 {
00268 if (id != rhs.id) return false;
00269 if (from == to && rhs.from != rhs.to) {
00270 return from >= rhs.from && from < rhs.to;
00271 }
00272 if (rhs.from == rhs.to && from != to) {
00273 return rhs.from >= from && rhs.from < to;
00274 }
00275 return from == rhs.from && to == rhs.to;
00276 }
00277
00278
00279
00280
00281
00282
00283 template<typename I>
00284 inline bool IdPeriod<I>::operator<(const IdPeriod& rhs) const
00285 {
00286 if (id != rhs.id) return id < rhs.id;
00287 if (from != to && rhs.from == rhs.to) return to <= rhs.from;
00288 return from < rhs.from;
00289 }
00290
00291 template<typename I>
00292 inline bool IdPeriod<I>::operator!=(const IdPeriod& rhs) const
00293 {
00294 return !(*this == rhs);
00295 }
00296
00297 template<typename I>
00298 inline bool IdPeriod<I>::operator>(const IdPeriod& rhs) const
00299 {
00300 return rhs < *this;
00301 }
00302 }
00303 #endif // #ifndef _OSBUTILS_H_