COPASI API  4.16.103
CLStyle.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/layout/CLStyle.cpp,v $
3 // $Revision: 1.6 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/23 15:44:52 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include <sstream>
15 
16 #include <sbml/packages/render/sbml/Style.h>
17 
18 #include "CLStyle.h"
19 
22 
23 /**
24  * Constructor.
25  */
26 CLStyle::CLStyle(const std::string& name, CCopasiContainer* pParent):
27  CLBase(),
28  CCopasiContainer(name, pParent),
29  mpGroup(NULL),
30  mKey("")
31 {
32 }
33 
34 /**
35  * Copy Constructor.
36  */
37 CLStyle::CLStyle(const CLStyle& source, CCopasiContainer* pParent):
38  CLBase(source),
39  CCopasiContainer(source, pParent),
40  mRoleList(source.mRoleList),
41  mTypeList(source.mTypeList),
42  mpGroup(NULL),
43  mKey("")
44 {
45  if (source.mpGroup != NULL)
46  {
47  this->mpGroup = new CLGroup(*source.mpGroup, this);
48  }
49 }
50 
51 /**
52  * Constructor to generate object from the corresponding SBML object.
53  */
54 CLStyle::CLStyle(const Style& source, const std::string& name, CCopasiContainer* pParent):
55  CLBase(),
56  CCopasiContainer(name, pParent),
57  mpGroup(new CLGroup(*source.getGroup(), this)),
58  mKey("")
59 {
60  CLStyle::readIntoSet(CLStyle::createStringFromSet(source.getRoleList()), this->mRoleList);
61  CLStyle::readIntoSet(CLStyle::createStringFromSet(source.getTypeList()), this->mTypeList);
62 }
63 
64 /**
65  * Destructor
66  */
68 {
70 }
71 
72 /**
73  * Sets the group.
74  */
75 void CLStyle::setGroup(const CLGroup* pGroup)
76 {
77  if (pGroup)
78  {
79  if (this->mpGroup != NULL)
80  {
81  delete this->mpGroup;
82  }
83 
84  this->mpGroup = new CLGroup(*pGroup, this);
85  }
86 }
87 
88 /**
89  * Returns the group.
90  */
91 const CLGroup* CLStyle::getGroup() const
92 {
93  return this->mpGroup;
94 }
95 
96 /**
97  * Returns the group.
98  */
100 {
101  return this->mpGroup;
102 }
103 
104 /**
105  * Returns the number roles ids in the role list.
106  */
107 size_t CLStyle::getNumRoles() const
108 {
109  return this->mRoleList.size();
110 }
111 
112 /**
113  * Adds an role to the role list.
114  */
115 void CLStyle::addRole(const std::string& role)
116 {
117  this->mRoleList.insert(role);
118 }
119 
120 /**
121  * Checks whether a given role is in the role list.
122  */
123 bool CLStyle::isInRoleList(const std::string& role) const
124 {
125  return (this->mRoleList.find(role) != this->mRoleList.end());
126 }
127 
128 /**
129  * Removes an role from the role list.
130  */
131 void CLStyle::removeRole(const std::string& role)
132 {
133  this->mRoleList.erase(role);
134 }
135 
136 /**
137  * Returns the number of types in the type list.
138  */
139 size_t CLStyle::getNumTypes() const
140 {
141  return this->mTypeList.size();
142 }
143 
144 /**
145  * Adds an type to the type list.
146  */
147 void CLStyle::addType(const std::string& type)
148 {
149  this->mTypeList.insert(type);
150 }
151 
152 /**
153  * Checks whether a given type is in the type list.
154  */
155 bool CLStyle::isInTypeList(const std::string& type) const
156 {
157  return (this->mTypeList.find(type) != this->mTypeList.end());
158 }
159 
160 /**
161  * Removes an type from the type list.
162  */
163 void CLStyle::removeType(const std::string& type)
164 {
165  this->mTypeList.erase(type);
166 }
167 
168 void CLStyle::readIntoSet(const std::string& s, std::set<std::string>& set)
169 {
170  std::string delimiter = "\n\r\t ";
171  std::size_t lastPos = s.find_first_not_of(delimiter);
172  std::size_t pos;
173 
174  while (lastPos != std::string::npos)
175  {
176  pos = s.find_first_of(delimiter, lastPos);
177  set.insert(s.substr(lastPos, pos - lastPos));
178  lastPos = s.find_first_not_of(delimiter, pos);
179  }
180 }
181 
182 std::string CLStyle::createStringFromSet(const std::set<std::string>& set)
183 {
184  std::ostringstream os;
185  std::set<std::string>::const_iterator it = set.begin(), endit = set.end();
186 
187  while (it != endit)
188  {
189  os << *it << " ";
190  ++it;
191  }
192 
193  if (!os.str().empty())
194  {
195  os.str(os.str().substr(0, os.str().size() - 1));
196  }
197 
198  return os.str();
199 }
200 
201 const std::set<std::string>& CLStyle::getRoleList() const
202 {
203  return this->mRoleList;
204 }
205 
206 const std::set<std::string>& CLStyle::getTypeList() const
207 {
208  return this->mTypeList;
209 }
210 
211 void CLStyle::setRoleList(const std::set<std::string>& roleList)
212 {
213  // I do not check roles on purpose since this is more versatil in the light
214  // of future extensions
215  this->mRoleList = roleList;
216 }
217 
218 void CLStyle::setTypeList(const std::set<std::string>& typeList)
219 {
220  // I do not check types on purpose since this is more versatil in the light
221  // of future extensions
222  this->mTypeList = typeList;
223 }
224 
225 /**
226  * Returns the key of the style
227  */
228 const std::string& CLStyle::getKey() const
229 {
230  return this->mKey;
231 }
232 
233 /**
234  * Adds the attributes for a style object to the passed in.
235  * object.
236  */
237 void CLStyle::addSBMLAttributes(Style* pStyle) const
238 {
239  RenderGroup* pG = this->mpGroup->toSBML(pStyle->getLevel(), pStyle->getVersion());
240  pStyle->setGroup(pG);
241  delete pG;
242  std::set<std::string> s;
244  pStyle->setRoleList(s);
245  s.clear();
247  pStyle->setTypeList(s);
248 }
size_t getNumTypes() const
Definition: CLStyle.cpp:139
bool remove(const std::string &key)
void removeType(const std::string &type)
Definition: CLStyle.cpp:163
void removeRole(const std::string &role)
Definition: CLStyle.cpp:131
~CLStyle()
Definition: CLStyle.cpp:67
void setGroup(const CLGroup *pGroup)
Definition: CLStyle.cpp:75
void addRole(const std::string &role)
Definition: CLStyle.cpp:115
static void readIntoSet(const std::string &s, std::set< std::string > &set)
Definition: CLStyle.cpp:168
void addType(const std::string &type)
Definition: CLStyle.cpp:147
std::string mKey
Definition: CLStyle.h:41
CLGroup * mpGroup
Definition: CLStyle.h:36
const std::set< std::string > & getRoleList() const
Definition: CLStyle.cpp:201
size_t getNumRoles() const
Definition: CLStyle.cpp:107
const std::set< std::string > & getTypeList() const
Definition: CLStyle.cpp:206
std::set< std::string > mTypeList
Definition: CLStyle.h:35
const CLGroup * getGroup() const
Definition: CLStyle.cpp:91
void addSBMLAttributes(Style *pStyle) const
Definition: CLStyle.cpp:237
Definition: CLBase.h:33
void setTypeList(const std::set< std::string > &typeList)
Definition: CLStyle.cpp:218
const std::string & getKey() const
Definition: CLStyle.cpp:228
static CKeyFactory * getKeyFactory()
CLStyle(const std::string &name, CCopasiContainer *pParent=NULL)
Definition: CLStyle.cpp:26
bool isInTypeList(const std::string &type) const
Definition: CLStyle.cpp:155
static std::string createStringFromSet(const std::set< std::string > &set)
Definition: CLStyle.cpp:182
bool isInRoleList(const std::string &role) const
Definition: CLStyle.cpp:123
std::set< std::string > mRoleList
Definition: CLStyle.h:34
void setRoleList(const std::set< std::string > &roleList)
Definition: CLStyle.cpp:211
RenderGroup * toSBML(unsigned int level, unsigned int version) const
Definition: CLGroup.cpp:799