// StdObjStream.hpp #ifndef StdObjStream_H #define StdObjStream_H // Implementation of Objstream. The format is // // [ oname otype aname_1=value_1 aname_2=value_2 ... ] // // where // oname = object name // otype = object type // aname_i = name for attribute i // value_i = value for attribute i // // These fields are delimited with white space (space, tab or end of // line). White space around the '=' is optional. The types of the // attributes are implied by their format: // // INT - All characters are digits. // DOUBLE - Usual floating format except exactly one '.' must appear. // BOOL - true or false // STRING - delimited by double quotes, e.g.: "This is my string." // BARE_PTR - name preceeded with '*', e.g. *psurf // SHAR_PTR - name preceeded with '@', e.g.: @plyr // // All names may contain only letters, digits or underscores and the // first character may not be a digit. // // Symbols may be used to assign values. The symbol values must be // in the format appropriate to the type of value. Th symbol names // must meet the format for other names. Use $sym_name in place of a // value where sym_name is the symbol name. // // Symbols must be predefined (Pi, TWOPI, PI2, ...) or defined before // their use. // // The special symbols OBSDEBUG and OBS_GLOBAL_DEBUG puts StdobjStream into a verbose // mode if it has the value true. // // Lines beginning with '#' are ignored. These may not appear inside // object or symbol definitions. // #include #include "ObjStream.hpp" #include "ObjException.hpp" #include using std::string; using std::vector; class StdObjStream : public ObjStream { private: // typedefs // Map of symbols indexed by name. typedef std::map< string, string, std::less > SymbolMap; // Vector for storing names of files and streams read typedef std::vector< string > StFilNameVector; private: // data // Map of symbols. SymbolMap _symbols; // Vector with names of stream and files read StFilNameVector _names; private: // methods // Return input stream after verifying that the state is good. istream& good_in_stream(); // Return output stream after verifying that the state is good. ostream& good_out_stream(); // Return the value for a symbol. // Returns "" if symbol is undefined. string symval(string name) const; // Return if we are in debug mode. // This is true if the symbol OBSDEBUG is set to true. void debug_message(string); // Read in a object. string read_data(); string read_symbols(istream& inpstream); string read_data_helper(string word); // Write out an object. void write_data(string name, const ObjData& data); public: // Constructor from an input stream. StdObjStream(istream& stream); // Constructor from an output stream. StdObjStream(ostream& stream); }; // Exceptions. class StdObjReadError : public ObjException { public: StdObjReadError(istream& stream); }; class StdObjWriteError : public ObjException { public: StdObjWriteError(ostream& stream); }; class StdUnableToCreateObject : public ObjException { public: StdUnableToCreateObject(string otype); }; class StdObjUnknownSymbol : public StdObjReadError { public: StdObjUnknownSymbol(istream& stream, string sname); }; #endif