cel_datastore.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00004 //
00005 // (C) 2003-2006 Celartem Technology Inc. All rights reserved.
00006 //----------------------------------------------------------------------------
00007 
00008 #ifndef _cel_datastore_h_
00009 #define _cel_datastore_h_
00010 
00011 #include "cel_string.h"
00012 #include "cel_autoptr.h"
00013 #include "cel_guid.h"
00014 #include "cel_time.h"
00015 #include "cel_serializable.h"
00016 #include "cel_exception.h"
00017 
00018 namespace Celartem
00019 {
00020     class Stream;
00021     class BasicDataArray;
00022 
00031     class DataStore : public Serializable
00032     {
00033     public:
00034         //--------------------------------------------------------------------
00046         virtual AutoPtr<DataStore> addDataStore(
00047             const String& inName, UChar4 pathSep = '\0') = 0;
00048 
00062         virtual void set(
00063             const String& inName, Serializable *inSerializable,
00064             UChar4 pathSep = '\0') = 0;
00065 
00079         template<typename T> void setT(
00080             const String& inName, const T& inValue,
00081             UChar4 pathSep = '\0')
00082         {
00083             set(inName, new SerializableData<T>(inValue), pathSep);
00084         }
00085 
00086 
00093         virtual size_t getSize() const = 0;
00094 
00102         virtual String getName(size_t inIndex) const = 0;
00103 
00111         virtual AutoPtr<Serializable> at(size_t inIndex) = 0;
00112 
00120         virtual AutoPtr<const Serializable> at(size_t inIndex) const = 0;
00121 
00134         template<class T> AutoPtr<T> at(size_t inIndex)
00135         {
00136             AutoPtr<Serializable> s = at(inIndex);
00137             T *p = dynamic_cast<T *>(s.getPtr());
00138             if(!p)
00139                 celThrow(errTypeMismatch);
00140             return p;
00141         }
00142 
00155         template<class T> AutoPtr<const T> at(size_t inIndex) const
00156         {
00157             AutoPtr<const Serializable> s = at(inIndex);
00158             const T *p = dynamic_cast<const T *>(s.getPtr());
00159             if(!p)
00160                 celThrow(errTypeMismatch);
00161             return p;
00162         }
00163 
00174         virtual AutoPtr<Serializable> get(
00175             const String& inName, UChar4 pathSep = '\0') = 0;
00176 
00187         virtual AutoPtr<const Serializable> get(
00188             const String& inName, UChar4 pathSep = '\0') const = 0;
00189 
00205         template<class T> AutoPtr<T> get(
00206             const String& inName, UChar4 pathSep = '\0')
00207         {
00208             AutoPtr<Serializable> s = get(inName, pathSep);
00209             T *p = dynamic_cast<T *>(s.getPtr());
00210             if(!p)
00211             {
00212                 celThrow2(
00213                     errTypeMismatch,
00214                     TO_MBS(format_utf8(
00215                         "Although the object type is %s, "
00216                         "you requested %s.",
00217                         Serializable::getClassName(
00218                             typeid(*s).name()).c_str(),
00219                         Serializable::getClassName(
00220                             typeid(T).name()).c_str()
00221                         )));
00222             }
00223             return p;
00224         }
00225 
00242         template<class T> AutoPtr<const T> get(
00243             const String& inName, UChar4 pathSep = '\0') const
00244         {
00245             AutoPtr<const Serializable> s = get(inName, pathSep);
00246             const T *p = dynamic_cast<const T *>(s.getPtr());
00247             if(!p)
00248                 celThrow(errTypeMismatch);
00249             return p;
00250         }
00251 
00261         virtual void unlink(const String& inName, UChar4 pathSep = '\0') = 0;
00262 
00263         //--------------------------------------------------------------------
00277         void setProperty_U64(
00278             const String& inName, uint64_t v, UChar4 pathSep = '\0');
00279 
00293         void setProperty_I64(
00294             const String& inName, int64_t v, UChar4 pathSep = '\0');
00295 
00309         void setProperty_U32(
00310             const String& inName, u32 v, UChar4 pathSep = '\0');
00311 
00325         void setProperty_I32(
00326             const String& inName, i32 v, UChar4 pathSep = '\0');
00327 
00341         void setProperty_Double(
00342             const String& inName, double v, UChar4 pathSep = '\0');
00343 
00357         void setProperty(
00358             const String& inName, size_t v, UChar4 pathSep = '\0');
00359 
00373         void setProperty(
00374             const String& inName, const char *v, UChar4 pathSep = '\0');
00375 
00389         void setProperty(
00390             const String& inName, const utf8s& v, UChar4 pathSep = '\0');
00391 
00405         void setProperty(
00406             const String& inName, const String& v, UChar4 pathSep = '\0');
00407 
00421         void setProperty(
00422             const String& inName, const Time& v, UChar4 pathSep = '\0');
00423 
00437         void setProperty(
00438             const String& inName, const TimeSpan& v, UChar4 pathSep = '\0');
00439 
00453         void setProperty(
00454             const String& inName, const Guid& v, UChar4 pathSep = '\0');
00455 
00469         void setProperty(
00470             const String& inName, Serializable *inSerializable,
00471             UChar4 pathSep = '\0');
00472 
00473         //--------------------------------------------------------------------
00487         AutoPtr<DataStore> getAsDataStore(
00488             const String& inName, UChar4 pathSep = '\0');
00489 
00503         AutoPtr<const DataStore> getAsDataStore(
00504             const String& inName, UChar4 pathSep = '\0') const;
00505 
00506         //--------------------------------------------------------------------
00520         AutoPtr<BasicDataArray> getAsDataArray(
00521             const String& inName, UChar4 pathSep = '\0');
00522 
00536         AutoPtr<const BasicDataArray> getAsDataArray(
00537             const String& inName, UChar4 pathSep = '\0') const;
00538 
00552         ssize_t getAsInteger(
00553             const String& inName, UChar4 pathSep = '\0') const;
00554 
00568         size_t getAsUInteger(
00569             const String& inName, UChar4 pathSep = '\0') const;
00570 
00584         int64_t getAsInteger64(
00585             const String& inName, UChar4 pathSep = '\0') const;
00586 
00600         uint64_t getAsUInteger64(
00601             const String& inName, UChar4 pathSep = '\0') const;
00602 
00616         double getAsDouble(
00617             const String& inName, UChar4 pathSep = '\0') const;
00618 
00632         String getAsString(
00633             const String& inName, UChar4 pathSep = '\0') const;
00634 
00648         Time getAsTime(
00649             const String& inName, UChar4 pathSep = '\0') const;
00650 
00664         TimeSpan getAsTimeSpan(
00665             const String& inName, UChar4 pathSep = '\0') const;
00666 
00680         Guid getAsGUID(
00681             const String& inName, UChar4 pathSep = '\0') const;
00682 
00683         //--------------------------------------------------------------------
00694         bool doesExist(const String& inName, UChar4 pathSep = '\0') const;
00695 
00696         //--------------------------------------------------------------------
00707         String getClassOf(const String& inName, UChar4 pathSep = '\0') const;
00708 
00719         const Guid& getClassIdOf(
00720             const String& inName, UChar4 pathSep = '\0') const;
00721 
00722         //--------------------------------------------------------------------
00728         static AutoPtr<DataStore> create();
00729 
00741         static AutoPtr<DataStore> create(
00742             Stream *inStream);
00743 
00744         //--------------------------------------------------------------------
00762         static AutoPtr<Serializable> deserialize(
00763             Stream *inStream, size_t inLevel = 0, Endian inEndian = endianBig);
00764 
00765         //--------------------------------------------------------------------
00770         virtual void instructNoChecksum() = 0;
00771 
00772         //--------------------------------------------------------------------
00778         virtual AutoPtr<DataStore> duplicateDataStore() = 0;
00779     };
00780 
00781 
00782 } // namespace Celartem
00783 
00784 #endif // _cel_datastore_h_

This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:21:54 2008.