Scopira 20080306

polyflow.h

00001 
00002 /*
00003  *  Copyright (c) 2002-2007    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_POLYFLOW_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_POLYFLOW_H__
00016 
00017 #include <scopira/tool/flow.h>
00018 #include <scopira/tool/export.h>
00019 
00020 #include <typeinfo>
00021 #include <map>
00022 
00023 //
00024 // two polymorphic flow implementations
00025 // (rouge wave guide, ver 7, p124)
00026 //
00027 // @author Aleksander Demko
00028 //
00029 
00030 namespace scopira
00031 {
00032   namespace tool
00033   {
00034     class polyiflow;
00035     class polyoflow;
00036     class isoiflow;
00037     class isooflow;
00038   }
00039 }
00040 
00051 class scopira::tool::polyiflow : public scopira::tool::iobjflow_i
00052 {
00053   protected:
00054     bool read_object_impl(object* &out);
00055     typedef std::map<int, const std::type_info*> typemap_t;
00056     count2_ptr< itflow_i > dm_file;
00057     typemap_t dm_typemap;
00058 
00059   public:
00060   
00062     SCOPIRA_EXPORT polyiflow(bool doref, itflow_i* rz);
00063     
00065     SCOPIRA_EXPORT virtual ~polyiflow();
00066 
00068     SCOPIRA_EXPORT virtual bool failed(void) const;
00069     
00071     SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
00072 
00073     SCOPIRA_EXPORT virtual bool read_bool(bool&);
00074     SCOPIRA_EXPORT virtual bool read_char(char&);
00075     SCOPIRA_EXPORT virtual bool read_short(short&);
00076     SCOPIRA_EXPORT virtual bool read_int(int&);
00077     SCOPIRA_EXPORT virtual bool read_size_t(size_t&);
00078     SCOPIRA_EXPORT virtual bool read_int64_t(int64_t&);
00079     SCOPIRA_EXPORT virtual bool read_long(long&);
00080     SCOPIRA_EXPORT virtual bool read_float(float&);
00081     SCOPIRA_EXPORT virtual bool read_double(double&);
00082     SCOPIRA_EXPORT virtual bool read_string(std::string&);
00083     
00085     SCOPIRA_EXPORT virtual bool read_object(object* &out);
00086     
00094     SCOPIRA_EXPORT void open(itflow_i* fi);
00095     
00097     SCOPIRA_EXPORT void close(void);
00098 };
00099 
00110 class scopira::tool::polyoflow : public scopira::tool::oobjflow_i
00111 {   
00112   protected:
00113     typedef std::map<std::string, int> typemap_t;
00114     count2_ptr< otflow_i > dm_file;
00115     int dm_next_typeid;
00116     typemap_t dm_typemap;
00117 
00118   public:
00119   
00121     SCOPIRA_EXPORT polyoflow(bool doref, otflow_i* rz);
00122     
00124     SCOPIRA_EXPORT virtual ~polyoflow();
00125 
00127     SCOPIRA_EXPORT virtual bool failed(void) const;
00128     
00130     SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
00131 
00132     SCOPIRA_EXPORT virtual void write_bool(bool val);
00133     SCOPIRA_EXPORT virtual void write_char(char val);
00134     SCOPIRA_EXPORT virtual void write_short(short val);
00135     SCOPIRA_EXPORT virtual void write_int(int val);
00136     SCOPIRA_EXPORT virtual void write_size_t(size_t val);
00137     SCOPIRA_EXPORT virtual void write_int64_t(int64_t val);
00138     SCOPIRA_EXPORT virtual void write_long(long val);
00139     SCOPIRA_EXPORT virtual void write_float(float val);
00140     SCOPIRA_EXPORT virtual void write_double(double val);
00141     SCOPIRA_EXPORT virtual void write_string(const std::string& val);
00142     
00144     SCOPIRA_EXPORT virtual void write_object(const scopira::tool::object* o);
00145     
00153     SCOPIRA_EXPORT void open(otflow_i* fi);
00154     
00156     SCOPIRA_EXPORT void close(void);
00157 };
00158 
00172 class scopira::tool::isoiflow : public scopira::tool::polyiflow
00173 {
00174   protected:
00175     typedef std::map<int, scopira::tool::object*> idmap_t;
00176     idmap_t dm_idmap;
00177 
00178   public:  
00180     SCOPIRA_EXPORT isoiflow(bool doref, itflow_i* rz);
00181     
00183     SCOPIRA_EXPORT virtual ~isoiflow();
00184     
00186     SCOPIRA_EXPORT virtual bool read_object(object* &out);
00187 };
00188 
00202 class scopira::tool::isooflow : public scopira::tool::polyoflow
00203 {
00204   protected:
00205     typedef std::map<const scopira::tool::object*, int> ptrmap_t;
00206     int dm_nextid;
00207     ptrmap_t dm_ptrmap;
00208 
00209   public:
00211     SCOPIRA_EXPORT isooflow(bool doref, otflow_i* rz);
00212     
00214     SCOPIRA_EXPORT virtual ~isooflow();
00215     
00217     SCOPIRA_EXPORT virtual void write_object(const scopira::tool::object* o);
00218 };
00219 
00220 #endif
00221