#ifndef ATTRPARSE_H #define ATTRPARSE_H //$Id: AttrParse.h,v 1.12 2006/08/09 16:36:11 markus Rel $ // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef _MSC_VER #pragma warning(disable:4786) // disable warning about truncating debug info #endif #include #include #include #include namespace YGP { // Macros to set the attribute-values to parse into the attribute-parser #define ATTRIBUTE(APobj, type, var, name) APobj.addAttribute (*new YGP::Attribute (name, var)); #define MEATTRIBUTE(APobj, meobj, var, name) APobj.addAttribute (*new YGP::MetaEnumAttribute (name, meobj, var)); /**Class to parse attribute-assignments from a string and sets its values into attribute-values. Use this class like the following: \verbatim std::string file; ANumeric size; ATimestamp time; AttributeParse attrs; ATTRIBUTE (attrs, std::string, file, "File"); ATTRIBUTE (attrs, ANumeric, size, "Size"); ATTRIBUTE (attrs, ATimestamp, time, "Time"); try { attrs.assignValues ("File=\"ADate.cpp\";Time=01012000 121005;Size=18180"); } catch (YGP::ParseError& e) { // Errorhandling } \endverbatim This example would assign the values \c ADate.cpp to \c file, \c 18180 to \c size and the 1st of January 2000, 12:10:05 to \c time. MEATTRIBUTE defines an attribute whose values are restricted to the values in the respective YGP::MetaEnum. \note Tthe order of the attributes while declaration and during parsing does not need to be the same! */ class AttributeParse { public: //Section manager-functions AttributeParse () { } ///< Default constructor; creates an empty object virtual ~AttributeParse (); void assignValues (const std::string& values) const throw (YGP::ParseError); void addAttribute (IAttribute& attr); const IAttribute* findAttribute (const std::string& name) const; const IAttribute* findAttribute (const char* name) const; private: AttributeParse (const AttributeParse&); AttributeParse& operator= (const AttributeParse&); IAttribute** attrs; // Pointer to array holding attributes std::vector apAttrs; }; } #endif