00001 /* -*- Mode: c++ -*- */ 00002 /* 00003 * this is part of Spm 00004 * 00005 * Copyright (c) 2005-2008 Guillaume Chevallereau 00006 * 00007 * This program is free software. You can redistribute it and/or modify it 00008 * under the terms of the GNU General Public License as published by the 00009 * Free Software Foundation. Either version 2 of the license or (at your 00010 * option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be usefull but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00015 * more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00020 */ 00021 #ifndef __ELEMENT_H__ 00022 #define __ELEMENT_H__ 00023 00024 #include <vector> 00025 #include <util/object.h> 00026 #include "versionned.h" 00027 #include "category.h" 00028 00029 #include <functional> 00030 #include <algorithm> 00031 00032 namespace Spm 00033 { 00034 namespace Core 00035 { 00036 class Element : public Util::Object 00037 { 00038 friend class ElementStore; 00039 public : 00040 typedef std::vector<Versionned *>::iterator iterator; 00041 typedef std::vector<Versionned *>::const_iterator const_iterator; 00042 typedef std::vector<Versionned *>::reverse_iterator reverse_iterator; 00043 typedef std::vector<Versionned *>::const_reverse_iterator const_reverse_iterator; 00044 protected: 00045 Category * category; 00046 miniXml::ustring description; 00047 miniXml::ustring elementURL; 00048 std::vector<Versionned *> versions_; 00049 Element (); 00050 00051 public: 00052 static void formatName (miniXml::ustring & version); 00053 virtual ~Element (); 00054 00058 const miniXml::ustring & getDescription (); 00059 00063 const miniXml::ustring & getDescription () const; 00064 00068 void setName (const miniXml::ustring & name); 00069 00073 void setDescription (const miniXml::ustring & description); 00074 00078 const Category * getCategory (); 00079 00083 const Category * getCategory () const; 00084 00088 void setCategory (Category * aCategory); 00089 00093 void add (Versionned * aBranch); 00094 00098 Versionned * remove (const miniXml::ustring & aBranch); 00099 00103 std::vector<Versionned *> & getVersions (); 00104 const std::vector<Versionned *> & getVersions () const; 00105 00110 const Versionned * getVersionned (const miniXml::ustring & branchName) const; 00111 00116 Versionned * getVersionned (const miniXml::ustring & branchName); 00117 00118 00119 Versionned * remove (Versionned * branch); 00120 00121 iterator find (Versionned * branch) 00122 { 00123 return std::find (versions_.begin (), 00124 versions_.end (), 00125 branch); 00126 } 00127 00128 const_iterator find (Versionned * branch) const 00129 { 00130 return std::find (versions_.begin (), 00131 versions_.end (), 00132 branch); 00133 } 00134 00135 iterator find (const miniXml::ustring & name); 00136 00137 const_iterator find (const miniXml::ustring & name) const; 00138 00139 bool operator< (const Element * e) const; 00140 bool operator< (const Element & e) const; 00141 00142 iterator begin () 00143 { 00144 return versions_.begin (); 00145 } 00146 00147 iterator end () 00148 { 00149 return versions_.end (); 00150 } 00151 00152 const_iterator begin () const 00153 { 00154 return versions_.begin (); 00155 } 00156 00157 const_iterator end () const 00158 { 00159 return versions_.end (); 00160 } 00161 00162 reverse_iterator rbegin () 00163 { 00164 return versions_.rbegin (); 00165 } 00166 00167 reverse_iterator rend () 00168 { 00169 return versions_.rend (); 00170 } 00171 00172 const_reverse_iterator rbegin () const 00173 { 00174 return versions_.rbegin (); 00175 } 00176 00177 const_reverse_iterator rend () const 00178 { 00179 return versions_.rend (); 00180 } 00181 00182 }; 00183 00187 struct equalElement : public std::binary_function<Element *, miniXml::ustring, bool> 00188 { 00189 bool operator() (Element * element, 00190 const miniXml::ustring & elementName) const; 00191 }; 00195 } 00196 } 00197 #endif