/* $Revision: 16 $ $Date: 25/05/05 11:51 $ Copyright © 2003-2006, FSL Technologies Limited. Contact "http://fost.3.felspar.com". */ #ifndef FOST_ID_HPP #define FOST_ID_HPP #pragma once #include #ifdef F3UTIL_EXPORTS #define FOST_ID_HPP_ARCHIVE L"$Archive: /FOST.3/F3Util/FOST.id.hpp $" #define FOST_ID_HPP_REVISION L"$Revision: 16 $" #define FOST_ID_HPP_DATE L"$Date: 25/05/05 11:51 $" #endif struct IFSLibFraction; namespace FSLib { class F3UTIL_DECLSPEC ID { public: inline ID() throw (); inline ID( long ); virtual inline ~ID() throw (); inline bool operator <( const ID & ) const throw (); inline bool operator <=( const ID &i ) const throw() { return !operator >( i ); } inline bool operator >( const ID & ) const throw (); inline bool operator >=( const ID &i ) const throw() { return !operator <( i ); } inline bool operator ==( const ID &i ) const throw () { return !operator !=( i ); } inline bool operator !=( const ID &i ) const throw () { return operator <( i ) || operator >( i ); } bool isnull() const { return m_id < 1; } inline FSLib::wstring asString() const; inline std::wostream &printOn( std::wostream & ) const; private: long m_id; }; inline F3UTIL_DECLSPEC std::wostream &operator <<( std::wostream &, const ID & ); inline F3UTIL_DECLSPEC ID nextID( const ID &domain ); inline F3UTIL_DECLSPEC ID currentID( const ID &domain ); namespace Mangling { template<> inline F3UTIL_DECLSPEC FSLib::wstring toSQL< ID >( const ID &, t_translation ) throw (std::bad_alloc); } namespace Exceptions { class F3UTIL_DECLSPEC IDFault : public Exception { public: inline IDFault( const FSLib::wstring & ); protected: inline const wchar_t * const message() const throw (); }; } template <> inline ID variant_cast( const VARIANT &v ) { return variant_cast< long >( v ); } template <> inline Nullable< ID > variant_cast( const VARIANT &v ) { if ( VARIANT_is_null( v ) ) return Null; return variant_cast< long >( v ); } namespace Private { class ValueIDCast { public: static void get( const ID &v, long *p ) { *p = _wtol( v.asString().c_str() ); } static void put( ID &v, const long &n ) { v = n; } }; class NullableIDCast { public: static void get( const FSLib::Nullable< ID > &v, VARIANT *p ) { if ( !v.isnull() ) { *p = _variant_t( _wtol( v.value().asString().c_str() ) ).Detach(); } else { *p = _variant_t().Detach(); } } static void put( FSLib::Nullable< ID > &v, const VARIANT *p ) { if ( VARIANT_is_null( *p ) || FSLib::VARIANT_to_wstring( *p ).length() == 0 ) { v = FSLib::Nullable< ID >(); } else { v = FSLib::variant_cast< ID >( *p ); } } }; } namespace Attribute { typedef ValueImpl< FSLib::ID, long, FSLib::Private::ValueIDCast > ValueID; typedef NullableImpl< FSLib::ID, long, FSLib::Private::NullableIDCast > NullableID; } } #endif // FOST_VALUES_HPP