COPASI API  4.16.103
CReference.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #include "copasi.h"
12 
13 #include "CRDFGraph.h"
14 #include "CModelMIRIAMInfo.h"
15 #include "CReference.h"
16 
17 #include "report/CKeyFactory.h"
19 #include "model/CModel.h"
21 
22 CReference::CReference(const std::string & objectName,
23  const CCopasiContainer * pParent):
24  CCopasiContainer(objectName, pParent, "Reference"),
25  mTriplet(),
26  mNodePath(),
27  mKey(CCopasiRootContainer::getKeyFactory()->add("Reference", this)),
28  mIdTriplet(),
29  mResource(NULL)
30 {}
31 
33  const std::string & objectName,
34  const CCopasiContainer * pParent):
35  CCopasiContainer(objectName, pParent, "Reference"),
36  mTriplet(triplet),
37  mNodePath(),
38  mKey(CCopasiRootContainer::getKeyFactory()->add("Creator", this)),
39  mIdTriplet(),
40  mResource(NULL)
41 {
42  if (!mTriplet)
43  return;
44 
46 
47  CRDFPredicate::ePredicateType Predicates[] =
48  {
53  };
54 
55  std::set< CRDFTriplet > Triples;
56 
57  CRDFPredicate::ePredicateType * pPredicate = Predicates;
58  std::set< CRDFTriplet >::iterator it;
59 
60  for (; *pPredicate != CRDFPredicate::end; ++pPredicate)
61  {
62  Triples = mTriplet.pObject->getDescendantsWithPredicate(*pPredicate);
63  it = Triples.begin();
64 
65  if (it != Triples.end())
66  {
67  mIdTriplet = *it;
69  }
70  }
71 }
72 
74  const CCopasiContainer * pParent):
75  CCopasiContainer(src, pParent),
76  mTriplet(src.mTriplet),
77  mNodePath(src.mNodePath),
78  mKey(CCopasiRootContainer::getKeyFactory()->add("Creator", this)),
79  mIdTriplet(src.mIdTriplet),
80  mResource(src.mResource)
81 {}
82 
84 {
86 }
87 
89 {return mTriplet;}
91 {
92  return mResource;
93 }
94 
95 const std::string & CReference::getKey() const
96 {return mKey;}
97 
98 std::string CReference::getResource() const
99 {return mResource.getDisplayName();}
100 
101 void CReference::setResource(const std::string & resource)
102 {
103  if (!mIdTriplet)
104  {
105  // We create an Id triplet
106  // This only adds the triplet if the resource is valid, i.e., it does not work;
107 
109 
110  std::set< CRDFTriplet > Triples;
111  std::set< CRDFTriplet >::iterator it;
112 
114  it = Triples.begin();
115 
116  if (it != Triples.end())
117  {
118  mIdTriplet = *it;
120  }
121  }
122 
123  if (mResource.setDisplayName(resource))
125 }
126 
127 const std::string & CReference::getId() const
128 {return mResource.getId();}
129 
130 void CReference::setId(const std::string & id)
131 {
132  if (!mIdTriplet)
133  {
134  // We create an Id triplet
136 
137  std::set< CRDFTriplet > Triples;
138  std::set< CRDFTriplet >::iterator it;
139 
141  it = Triples.begin();
142 
143  if (it != Triples.end())
144  {
145  mIdTriplet = *it;
147  }
148  }
149 
150  if (mResource.setId(id))
152 }
153 
154 std::string CReference::getURI() const
155 {return mResource.getURI();}
156 
157 const std::string & CReference::getDescription() const
159 
160 void CReference::setDescription(const std::string & description)
161 {
163 }
164 
166 {
167  // Empty descriptions are handled automatically since setFieldValue removes
168  // a triplet if the value is an empty string.
169 
170  // Handle invalid resource
171  if (!mResource.isValid() && mIdTriplet)
172  {
173  // We remove the Id triplet
175  mIdTriplet = CRDFTriplet(); // This makes it invalid.
176 
177  mResource.setURI("---");
178  }
179 }
bool remove(const std::string &key)
bool isValid() const
Definition: CConstants.cpp:182
std::string getResource() const
Definition: CReference.cpp:98
std::string getURI() const
Definition: CConstants.cpp:133
std::set< CRDFTriplet > getDescendantsWithPredicate(const CRDFPredicate &predicate) const
Definition: CRDFNode.cpp:398
void setId(const std::string &id)
Definition: CReference.cpp:130
const CMIRIAMResourceObject & getMIRIAMResourceObject() const
Definition: CReference.cpp:90
const std::string & getId() const
Definition: CReference.cpp:127
CRDFTriplet mIdTriplet
Definition: CReference.h:46
CMIRIAMResourceObject mResource
Definition: CReference.h:51
bool setURI(const std::string &URI)
Definition: CConstants.cpp:119
void setResource(const std::string &resource)
Definition: CReference.cpp:101
bool setId(const std::string &id)
Definition: CConstants.cpp:101
bool setDisplayName(const std::string &displayName)
Definition: CConstants.cpp:163
bool setNode(CRDFNode *pNode)
Definition: CConstants.cpp:150
std::string getURI() const
Definition: CReference.cpp:154
CRDFObject & getObject()
Definition: CRDFNode.cpp:94
bool setFieldValue(const CMIRIAMResourceObject &value, const CRDFPredicate::ePredicateType &predicate, const CRDFPredicate::Path &nodePath)
Definition: CRDFNode.cpp:142
void clearInvalidEntries()
Definition: CReference.cpp:165
CRDFPredicate::Path getPath() const
Definition: CRDFNode.cpp:110
std::string getDisplayName() const
Definition: CConstants.cpp:173
CRDFPredicate::Path mNodePath
Definition: CReference.h:36
const std::string & getId() const
Definition: CConstants.cpp:116
static CKeyFactory * getKeyFactory()
void setResource(const std::string &resource, const bool &isLocal)
Definition: CRDFObject.cpp:88
const std::string & getDescription() const
Definition: CReference.cpp:157
std::string mKey
Definition: CReference.h:41
void setDescription(const std::string &description)
Definition: CReference.cpp:160
virtual const std::string & getKey() const
Definition: CReference.cpp:95
const std::string & getFieldValue(const CRDFPredicate::ePredicateType &predicate) const
Definition: CRDFNode.cpp:113
const CRDFTriplet & getTriplet() const
Definition: CReference.cpp:88
CRDFNode * pObject
Definition: CRDFTriplet.h:42
CRDFTriplet mTriplet
Definition: CReference.h:31
CReference(const std::string &objectName, const CCopasiContainer *pParent=NULL)
Definition: CReference.cpp:22