/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2009 Oracle. All rights reserved. * * $Id$ */ #ifndef _DB_STL_PTYPE_H #define _DB_STL_PTYPE_H #include "dbstl_common.h" #include "dbstl_element_ref.h" #include using std::istream; using std::ostream; using namespace dbstl; ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // // ptype class template definition // // ptype<> is a primitive types wrapper, must use this wrapper to // store/retrieve primitive types to/from db via db stl interface // template class ptype { public: T v; ptype(){v = 0;} ptype(T vv){v = vv;} typedef ptype tptype; typedef db_vector_iterator dvit; operator T() { return v; } ptype(const ElementRef >&rval) { if ( rval._DB_STL_GetData(*this) != INVALID_KEY_DATA) { } else { throw new InvalidDbtException(); } } ptype(const ptype&p2) { v = p2.v; } template ptype(const ptype&p2) { v = p2.v; } template const ptype& operator=(const ptype&p2) { v = p2.v; return *this; } template const ptype operator +(const ptype &p2) const { return ptype(v + p2.v ); } template const ptype operator -(const ptype &p2) const { return ptype(v - p2.v ); } template const ptype operator *(const ptype &p2) const { return ptype(v * p2.v ); } template const ptype operator /(const ptype &p2) const { return ptype(v / p2.v ); } template const ptype operator %(const ptype &p2) const { return ptype(v % p2.v ); } template const ptype& operator +=(const ptype &p2) const { v += p2.v; return *this; } template const ptype& operator -=(const ptype &p2) const { v -= p2.v; return *this; } template const ptype& operator *=(const ptype &p2) const { v *= p2.v; return *this; } template const ptype& operator /=(const ptype &p2) const { v /= p2.v; return *this; } template const ptype& operator %=(const ptype &p2) const { v %= p2.v; return *this; } template bool operator==(const ptype&p2) const { return v == p2.v; } template bool operator!=(const ptype&p2)const { return v != p2.v; } template bool operator<(const ptype&p2) const { return v < p2.v; } template bool operator>(const ptype&p2) const { return v > p2.v; } template bool operator<=(const ptype&p2) const { return v <= p2.v; } template bool operator>=(const ptype&p2) const { return v >= p2.v; } const ptype& operator=(const ptype&p2) { v = p2.v; return p2; } bool operator>(const ptype&p2) const { return v > p2.v; } bool operator<(const ptype&p2) const { return v < p2.v; } bool operator>=(const ptype&p2) const { return v >= p2.v; } bool operator<=(const ptype&p2) const { return v <= p2.v; } const ptype operator-() const { return ptype(-v); } // althought the definitionos of following arithmetic operators are quite // alike, we can't define them using macros, seems macro's parameter can only // be symbols or literals, not operators const ptype operator +(const ptype &p2) const { return ptype(v + p2.v ); } const ptype operator -(const ptype &p2) const { return ptype(v - p2.v ); } const ptype operator *(const ptype &p2) const { return ptype(v * p2.v ); } const ptype operator /(const ptype &p2) const { return ptype(v / p2.v ); } const ptype operator %(const ptype &p2) const { return ptype(v % p2.v ); } const ptype& operator %=(const ptype &p2) const { v %= p2.v; return *this; } const ptype& operator +=(const ptype &p2) const { v += p2.v; return *this; } const ptype& operator -=(const ptype &p2) const { v -= p2.v; return *this; } const ptype& operator /=(const ptype &p2) const { v /= p2.v; return *this; } const ptype& operator *=(const ptype &p2) const { v *= p2.v; return *this; } }; // ptype // the following two functions help io ptype objs to/from any streams template basic_istream<_CharT,_Traits>& operator>>( basic_istream<_CharT,_Traits> & in, ptype&p) { in>>p.v; return in; } template basic_ostream<_CharT,_Traits>& operator<<( basic_ostream<_CharT,_Traits> & out, const ptype&p) { out< T operator * (T t, const ptype &pt) { return t * pt.v; } #endif // !_DB_STL_PTYPE_H