#ifndef ENTITY_H #define ENTITY_H //$Id: Entity.h,v 1.11 2006/05/03 20:53:56 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 #ifndef NO_HANDLE # include "Handle.h" #endif #include #include namespace YGP { /**Baseclass for classes holding (a list of) attributes The descrutor frees all managed attributes, so make sure to create them on the heap. Note that you can automatically manage the handled attributes with the utility \c mgeni (in the bin subdirectory). */ class Entity { friend class INIFile; public: /// Default constructor Entity () { }; virtual ~Entity (); IAttribute* findAttribute (const char* name) const; IAttribute* findAttribute (const std::string& name) const; /// Adds a new attribute to the entity. void addAttribute (IAttribute& newAttr) { Check3 (std::find (attributes.begin (), attributes.end (), &newAttr) == attributes.end ()); attributes.push_back (&newAttr); } friend std::ostream& operator<< (std::ostream& out, const Entity& obj) throw (); friend std::istream& operator>> (std::istream& in, Entity& obj) throw (); #ifdef __STL_MEMBER_TEMPLATES /// Add a copy of an attribute with a specific type to the entity. /// \note This is not portable! template void addAttribute (const char* name, const AttrType& attr) { Check1 (name); addAttribute (new Attribute (name, attr)); } /// Add a copy of an attribute with a specific type to the entity. /// \note This is not portable! template void addAttribute (const std::string& name, const AttrType& attr) { addAttribute (new Attribute (name, attr)); } #endif private: std::vector attributes; }; #ifndef NO_HANDLE /// Defines a handle (smart pointer with reference counting) to an Entity defineHndl (Entity); #endif } #endif