1 /* 2 * HT Editor 3 * store.h 4 * 5 * Copyright (C) 1999-2003 Sebastian Biallas (sb@biallas.net) 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef STORE_H 22 #define STORE_H 23 24 #include "data.h" 25 #include "sys/types.h" 26 27 typedef Object *(*object_builder)(); 28 29 #include "stream.h" 30 #include "except.h" 31 32 class ObjectNotRegisteredException: public MsgfException { 33 ObjectID mID; 34 public: 35 ObjectNotRegisteredException(ObjectID aID); 36 }; 37 38 class ObjectStreamInter: public ObjectStream { 39 public: ObjectStreamInter(Stream * s,bool own_stream)40 ObjectStreamInter(Stream *s, bool own_stream) : ObjectStream(s, own_stream) {}; 41 /* extends ObjectStream */ 42 virtual Object *getObjectInternal(const char *name, ObjectID id = OBJID_INVALID); 43 virtual void putObject(const Object *object, const char *name, ObjectID id = OBJID_INVALID); 44 }; 45 46 class ObjectStreamBin: public ObjectStreamInter { 47 public: ObjectStreamBin(Stream * s,bool own_s)48 ObjectStreamBin(Stream *s, bool own_s): ObjectStreamInter(s, own_s) {}; 49 /* extends ObjectStream */ 50 virtual void getBinary(void *buf, uint size, const char *desc); 51 virtual bool getBool(const char *desc); 52 virtual uint64 getInt(uint size, const char *desc); 53 virtual char * getString(const char *desc); 54 virtual byte * getLenString(int &length, const char *desc); 55 56 virtual void putBinary(const void *mem, uint size, const char *desc); 57 virtual void putBool(bool b, const char *desc); 58 virtual void putComment(const char *comment); 59 virtual void putCommentf(const char *comment_format, ...); 60 virtual void putInt(uint64 i, uint size, const char *desc, uint int_fmt_hint = OS_FMT_DEC); 61 virtual void putSeparator(); 62 virtual void putString(const char *string, const char *desc); 63 virtual void putLenString(const byte *string, int length, const char *desc); 64 65 virtual void corrupt(); 66 }; 67 68 class ObjectStreamText: public ObjectStreamInter { 69 protected: 70 char cur; 71 int line; 72 int errorline; 73 int indent; 74 public: 75 76 ObjectStreamText(Stream *s, bool own_stream); 77 /* extends ObjectStreamInter */ 78 virtual Object * getObjectInternal(const char *name, ObjectID id = OBJID_INVALID); 79 virtual void putObject(const Object *object, const char *name, ObjectID id = OBJID_INVALID); 80 /* extends ObjectStream */ 81 virtual void getBinary(void *buf, uint size, const char *desc); 82 virtual bool getBool(const char *desc); 83 virtual uint64 getInt(uint size, const char *desc); 84 virtual char * getString(const char *desc); 85 virtual byte * getLenString(int &length, const char *desc); 86 87 virtual void putBinary(const void *mem, uint size, const char *desc); 88 virtual void putBool(bool b, const char *desc); 89 virtual void putComment(const char *comment); 90 virtual void putInt(uint64 i, uint size, const char *desc, uint int_fmt_hint = OS_FMT_DEC); 91 virtual void putSeparator(); 92 virtual void putString(const char *string, const char *desc); 93 virtual void putLenString(const byte *string, int length, const char *desc); 94 95 virtual void corrupt(); 96 97 void setSyntaxError(); 98 int getErrorLine(); 99 private: 100 /* io */ 101 void expect(char c); 102 void skipWhite(); 103 char readChar(); 104 void readDesc(const char *desc); 105 106 107 void putDesc(const char *desc); 108 void putIndent(); 109 void putChar(char c); 110 void putS(const char *s); 111 }; 112 113 /* 114 * ObjectStreamNative View:set/getData() methods 115 * (endian-dependend) 116 */ 117 118 #define DATABUF_BOOL(name) bool name PACKED 119 #define DATABUF_UINT(name) uint name PACKED 120 #define DATABUF_PTR(type, name) type* name PACKED 121 122 class ObjectStreamNative: public ObjectStream { 123 protected: 124 bool duplicate; 125 Array allocd; 126 127 void *duppa(const void *p, int size); 128 public: 129 ObjectStreamNative(Stream *s, bool own_s, bool duplicate); 130 /* extends ObjectStream */ 131 virtual void getBinary(void *buf, uint size, const char *desc); 132 virtual bool getBool(const char *desc); 133 virtual uint64 getInt(uint size, const char *desc); 134 virtual Object * getObjectInternal(const char *name, ObjectID id = OBJID_INVALID); 135 virtual char * getString(const char *desc); 136 virtual byte * getLenString(int &length, const char *desc); 137 138 virtual void putBinary(const void *mem, uint size, const char *desc); 139 virtual void putBool(bool b, const char *desc); 140 virtual void putComment(const char *comment); 141 virtual void putInt(uint64 i, uint size, const char *desc, uint int_fmt_hint = OS_FMT_DEC); 142 virtual void putObject(const Object *object, const char *name, ObjectID id = OBJID_INVALID); 143 virtual void putSeparator(); 144 virtual void putString(const char *string, const char *desc); 145 virtual void putLenString(const byte *string, int length, const char *desc); 146 147 virtual void corrupt(); 148 }; 149 150 void putIDComment(ObjectStream &o, uint32 id); 151 152 #endif 153