00001
00002 #ifndef LMSG_TRANSLATOR_HH
00003 #define LMSG_TRANSLATOR_HH
00004 #include "lmsg/MsgTypes.hh"
00005
00006 namespace lmsg {
00007 class Buffer;
00008 class MsgAddr;
00009 class Grinder;
00010
00022 class Translator {
00023 public:
00030 Translator(const char* fmt=0);
00031
00035 ~Translator(void);
00036
00058 error_type Define(const char* fmt);
00059
00068 error_type Export(const void* in, size_type length, Buffer& b);
00069
00079 error_type Import(const Buffer& b, void* out, size_type maxlen,
00080 size_type* len);
00081
00085 void Reset(void);
00086
00090 bool isHeaderOK(void) const;
00091
00094 bool isMultiBuffer(void) const;
00095
00098 void setHeaderOK(bool yesno=true);
00099
00102 void setMultiBuffer(bool yesno=true);
00103
00109 void setKeepNames(bool yesno=true);
00110
00111 private:
00112 enum tblop {
00113 o_AFmt=1, o_BFmt, o_DFmt, o_FFmt, o_IFmt, o_NIFmt, o_NSFmt, o_RFmt,
00114 o_SFmt, o_UBFmt, o_UIFmt, o_USFmt,
00115 o_Name, o_RepB, o_RepS, o_RepI, o_RepD,
00116 o_EndB, o_EndS, o_EndI, o_EndD, o_End, o_LTable};
00117 size_type fmtcd(const char* name, size_type len);
00118 size_type syntax(const char* fmt, size_type inx);
00119
00120 private:
00121 #define HEADEROKFLAG 1
00122 #define MULTIBUFFERFLAG 2
00123 size_type mFlags;
00124 size_type mOffset;
00125 size_type mOpCd;
00126 size_type mLevel;
00127 #define STACKSIZE 8
00128 size_type mLvPtr[STACKSIZE];
00129 size_type mLvRpt[STACKSIZE];
00130 #define NO_TRANS ((short*)-1)
00131 short* mFormat;
00132 bool mKeepNames;
00133
00134 private:
00135 static bool sTabSet;
00136 static size_type sTabLength[o_LTable];
00137 static size_type sTabAlign[o_LTable];
00138 };
00139
00140 }
00141
00142
00143 inline bool
00144 lmsg::Translator::isHeaderOK(void) const {
00145 return (mFlags & HEADEROKFLAG) != 0;
00146 }
00147
00148 inline void
00149 lmsg::Translator::setHeaderOK(bool yesno) {
00150 if (yesno) mFlags |= HEADEROKFLAG;
00151 else mFlags &= ~HEADEROKFLAG;
00152 }
00153
00154 inline bool
00155 lmsg::Translator::isMultiBuffer(void) const {
00156 return (mFlags & MULTIBUFFERFLAG) != 0;
00157 }
00158
00159 inline void
00160 lmsg::Translator::setMultiBuffer(bool yesno) {
00161 if (yesno) mFlags |= MULTIBUFFERFLAG;
00162 else mFlags &= ~MULTIBUFFERFLAG;
00163 }
00164
00165 inline void
00166 lmsg::Translator::setKeepNames(bool yesno) {
00167 mKeepNames = yesno;
00168 }
00169
00170 #endif // LMSG_TRANSLATOR_HH