00001 #ifndef __INSTANTIO_BASICCODEC_H
00002 #define __INSTANTIO_BASICCODEC_H
00003
00004 #ifdef _MSC_VER
00005 # pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "InstantIODef.h"
00027 #include "BasicEncoder.h"
00028 #include "TypeName.h"
00029 #include <map>
00030 #include <string>
00031 #ifdef __sgi
00032 # include <assert.h>
00033 #else
00034 # include <cassert>
00035 #endif
00036
00037
00038 namespace InstantIO
00039 {
00040
00041
00042 class BasicDecoder;
00043 class BasicOutSlot;
00044 class BasicInSlot;
00045
00046
00053 class INSTANTIO_DLLMAPPING BasicCodec
00054 {
00055 public:
00056
00058 typedef BasicEncoder *(*CreateEncoderMethod)();
00059
00061 typedef BasicDecoder *(*CreateDecoderMethod)();
00062
00064 typedef std::map<std::string, BasicCodec*> CodecMap;
00065
00067 virtual ~BasicCodec();
00068
00074 inline const std::string &getLabel() const { return label_; }
00075
00082 inline const std::string &getAuthor() const { return author_; }
00083
00090 virtual const char *getTypeName() const = 0;
00091
00096 inline BasicEncoder *createEncoder() const
00097 {
00098 assert(createEncoderMethod_ != 0);
00099 return createEncoderMethod_();
00100 }
00101
00106 inline BasicDecoder *createDecoder() const
00107 {
00108 assert(createDecoderMethod_ != 0);
00109 return createDecoderMethod_();
00110 }
00111
00119 static BasicCodec *findCodec(const std::string &label);
00120
00128 static BasicCodec *findCodec(const BasicOutSlot &outSlot);
00129
00137 static BasicCodec *findCodec(const BasicInSlot &inSlot);
00138
00145 virtual bool sameType(const BasicOutSlot &outSlot) const = 0;
00146
00153 virtual bool sameType(const BasicInSlot &inSlot) const = 0;
00154
00159 static inline CodecMap *getCodecs()
00160 { return codecMap_; }
00161
00162 protected:
00163
00174 BasicCodec(const std::string &label, CreateEncoderMethod createEncoderMethod, CreateDecoderMethod createDecoderMethod, const std::string &author = std::string());
00175
00176 private:
00177
00179 BasicCodec(const BasicCodec &);
00180
00182 const BasicCodec &operator=(const BasicCodec &);
00183
00185 static CodecMap *codecMap_;
00186
00188 std::string label_;
00189
00191 CreateEncoderMethod createEncoderMethod_;
00192
00194 CreateDecoderMethod createDecoderMethod_;
00195
00197 std::string author_;
00198 };
00199
00200
00201 }
00202
00203
00204 #endif // __INSTANTIO_BASICCODEC_H