00001 #ifndef __INSTANTIO_ENCODER_H
00002 #define __INSTANTIO_ENCODER_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 "InSlot.h"
00029 #include <string>
00030 #ifdef __sgi
00031 # include <assert.h>
00032 #else
00033 # include <cassert>
00034 #endif
00035
00036
00037 namespace InstantIO
00038 {
00039
00040
00041 class BasicInSlot;
00042
00043
00086 template <class T>
00087 class Encoder: public BasicEncoder
00088 {
00089 public:
00090
00092 virtual ~Encoder()
00093 { delete inSlot_; };
00094
00100 virtual void initialize(const std::string &label, const std::string &description)
00101 {
00102 BasicEncoder::initialize(label, description);
00103 inSlot_ = new InSlot<T>(description);
00104 };
00105
00111 virtual BasicInSlot *getInSlot() const
00112 {
00113 assert(inSlot_ != 0);
00114 return inSlot_;
00115 };
00116
00126 virtual void encode(std::ostream &os, const T &value) = 0;
00127
00128 protected:
00129
00131 inline Encoder(): BasicEncoder(), inSlot_(0) {}
00132
00139 virtual TimeStamp popAndEncode(std::ostream &os)
00140 {
00141 assert(inSlot_ != 0);
00142 Data<T> data = inSlot_->pop();
00143 encode(os, data.getValue());
00144 return data.getTimeStamp();
00145 };
00146
00147 private:
00148
00150 Encoder(const Encoder<T> &);
00151
00153 const Encoder<T> &operator=(const Encoder<T> &);
00154
00156 InSlot<T> *inSlot_;
00157 };
00158
00159
00160 }
00161
00162
00163 #endif // __INSTANTIO_ENCODER_H