COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CMIRIAMResourceObject Class Reference

#include <CConstants.h>

Collaboration diagram for CMIRIAMResourceObject:
Collaboration graph
[legend]

Public Member Functions

 CMIRIAMResourceObject (CRDFNode *pNode)
 
 CMIRIAMResourceObject (const std::string &displayName, const std::string &id)
 
 CMIRIAMResourceObject (const CMIRIAMResourceObject &src)
 
std::string getDisplayName () const
 
const std::string & getId () const
 
std::string getIdentifiersOrgURL () const
 
CRDFNodegetNode () const
 
size_t getResource (const std::string &URI)
 
std::string getURI () const
 
bool isValid () const
 
bool isValid (const std::string &URI) const
 
bool setDisplayName (const std::string &displayName)
 
bool setId (const std::string &id)
 
bool setNode (CRDFNode *pNode)
 
bool setURI (const std::string &URI)
 
virtual ~CMIRIAMResourceObject ()
 

Static Public Member Functions

static const CMIRIAMResourcesgetResourceList ()
 
static void setMIRIAMResources (const CMIRIAMResources *pResources)
 

Private Member Functions

 CMIRIAMResourceObject ()
 
void extractId (const std::string &URI)
 

Static Private Member Functions

static std::string trimId (const std::string &id)
 
static void unescapeId (std::string &id)
 

Private Attributes

std::string mId
 
CRDFNodempNode
 
size_t mResource
 

Static Private Attributes

static const CMIRIAMResourcesmpResources = NULL
 

Detailed Description

Definition at line 23 of file CConstants.h.

Constructor & Destructor Documentation

CMIRIAMResourceObject::CMIRIAMResourceObject ( )
private
CMIRIAMResourceObject::CMIRIAMResourceObject ( CRDFNode pNode)

Definition at line 72 of file CConstants.cpp.

References CRDFNode::getObject(), CRDFObject::getResource(), mpNode, and setURI().

72  :
73  mId(),
74  mpNode(pNode)
75 {
76  if (mpNode != NULL)
78 }
bool setURI(const std::string &URI)
Definition: CConstants.cpp:119
CRDFObject & getObject()
Definition: CRDFNode.cpp:94
const std::string & getResource() const
Definition: CRDFObject.cpp:94
CMIRIAMResourceObject::CMIRIAMResourceObject ( const std::string &  displayName,
const std::string &  id 
)

Definition at line 86 of file CConstants.cpp.

References mId, and setDisplayName().

86  :
88  mId(),
89  mpNode(NULL)
90 {
91  setDisplayName(displayName);
92  mId = id;
93 }
#define C_INVALID_INDEX
Definition: copasi.h:222
bool setDisplayName(const std::string &displayName)
Definition: CConstants.cpp:163
CMIRIAMResourceObject::CMIRIAMResourceObject ( const CMIRIAMResourceObject src)

Definition at line 95 of file CConstants.cpp.

95  :
96  mResource(src.mResource),
97  mId(src.mId),
98  mpNode(NULL)
99 {}
CMIRIAMResourceObject::~CMIRIAMResourceObject ( )
virtual

Destructor

Definition at line 262 of file CConstants.cpp.

263 {}

Member Function Documentation

void CMIRIAMResourceObject::extractId ( const std::string &  URI)
private

Definition at line 205 of file CConstants.cpp.

References CCopasiParameterGroup::beginIndex(), C_INVALID_INDEX, CCopasiParameterGroup::endIndex(), CMIRIAMResource::getIdentifiersOrgURL(), CMIRIAMResources::getMIRIAMResource(), CMIRIAMResource::getMIRIAMURI(), mId, mpResources, mResource, and unescapeId().

Referenced by setURI().

206 {
207  mId = "";
208 
209  // Check whether the resource is known.
210  if (mpResources == NULL ||
212  {
213  mId = URI;
214  return;
215  }
216 
217  int offset;
218  const std::string * pTmp = & mpResources->getMIRIAMResource(mResource).getMIRIAMURI();
219 
220  if (URI.substr(0, pTmp->length()) == *pTmp &&
221  URI.length() > pTmp->length())
222  {
223  offset = (pTmp->at(pTmp->length() - 1) == '/') ? 0 : 1;
224  mId = URI.substr(pTmp->length() + offset);
225  }
226 
227  if (mId == "")
228  {
230 
231  if (URI.substr(0, Tmp.length()) == Tmp &&
232  URI.length() > Tmp.length())
233  {
234  offset = (Tmp[Tmp.length() - 1] == '/') ? 0 : 1;
235  mId = URI.substr(Tmp.length() + offset);
236  }
237  }
238 
239  if (mId == "")
240  {
241  // We need to check for deprecated URIs
242  const CCopasiParameterGroup * pDeprecated = &(mpResources->getMIRIAMResource(mResource)).getMIRIAMDeprecated();
243  CCopasiParameterGroup::index_iterator itDeprecated = pDeprecated->beginIndex();
244  CCopasiParameterGroup::index_iterator endDeprecated = pDeprecated->endIndex();
245 
246  for (; itDeprecated != endDeprecated; ++itDeprecated)
247  if (URI.substr(0, (*itDeprecated)->getValue().pSTRING->length()) == *(*itDeprecated)->getValue().pSTRING &&
248  URI.length() > (*itDeprecated)->getValue().pSTRING->length())
249  {
250  const std::string& uri = *(*itDeprecated)->getValue().pSTRING;
251  offset = (uri[uri.length() - 1] == '/') ? 0 : 1;
252  mId = URI.substr(uri.length() + offset);
253  break;
254  }
255  }
256 
257  unescapeId(mId);
258 
259  return;
260 }
const std::string & getMIRIAMURI() const
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
std::string getIdentifiersOrgURL() const
const CMIRIAMResource & getMIRIAMResource(const size_t index) const
static void unescapeId(std::string &id)
Definition: CConstants.cpp:31
index_iterator endIndex() const
#define C_INVALID_INDEX
Definition: copasi.h:222
index_iterator beginIndex() const
parameterGroup::iterator index_iterator
std::string CMIRIAMResourceObject::getDisplayName ( ) const

Definition at line 173 of file CConstants.cpp.

References C_INVALID_INDEX, CMIRIAMResources::getMIRIAMResource(), mpResources, and mResource.

Referenced by CBiologicalDescription::getResource(), and CReference::getResource().

174 {
175  // Check whether the resource is known.
176  if (mResource == C_INVALID_INDEX)
177  return "";
178 
179  return (mpResources->getMIRIAMResource(mResource)).getMIRIAMDisplayName();
180 }
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
const CMIRIAMResource & getMIRIAMResource(const size_t index) const
#define C_INVALID_INDEX
Definition: copasi.h:222
const std::string & CMIRIAMResourceObject::getId ( ) const

Definition at line 116 of file CConstants.cpp.

References mId.

Referenced by CBiologicalDescription::getId(), and CReference::getId().

117 {return mId;}
std::string CMIRIAMResourceObject::getIdentifiersOrgURL ( ) const

Definition at line 138 of file CConstants.cpp.

References CMIRIAMResource::getIdentifiersOrgURL(), CMIRIAMResources::getMIRIAMResource(), mId, mpResources, and mResource.

Referenced by CQMiriamWidget::slotBtnBrowseDescription(), CQMiriamWidget::slotBtnBrowseReference(), and CSBMLExporter::updateMIRIAMAnnotation().

139 {
141 
142  if (URL == "http://identifiers.org/unknown")
143  {
144  return mId;
145  }
146 
147  return URL + "/" + mId;
148 }
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
std::string getIdentifiersOrgURL() const
const CMIRIAMResource & getMIRIAMResource(const size_t index) const
CRDFNode * CMIRIAMResourceObject::getNode ( ) const

Definition at line 160 of file CConstants.cpp.

References mpNode.

Referenced by CRDFNode::setFieldValue().

161 {return mpNode;}
size_t CMIRIAMResourceObject::getResource ( const std::string &  URI)

Definition at line 23 of file CConstants.cpp.

References CMIRIAMResources::getMIRIAMResourceIndex(), and mpResources.

Referenced by setURI().

24 {return mpResources->getMIRIAMResourceIndex(URI);}
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
size_t getMIRIAMResourceIndex(const std::string &URI) const
const CMIRIAMResources & CMIRIAMResourceObject::getResourceList ( )
static

Definition at line 27 of file CConstants.cpp.

References mpResources.

28 {return *mpResources;}
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
std::string CMIRIAMResourceObject::getURI ( ) const

Definition at line 133 of file CConstants.cpp.

References CMIRIAMResources::getMIRIAMResource(), mId, mpResources, and mResource.

Referenced by CBiologicalDescription::getURI(), CReference::getURI(), CRDFNode::setFieldValue(), CBiologicalDescription::setId(), CReference::setId(), CBiologicalDescription::setResource(), and CReference::setResource().

134 {
135  return (mpResources->getMIRIAMResource(mResource)).getMIRIAMURI() + ":" + mId;
136 }
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
const CMIRIAMResource & getMIRIAMResource(const size_t index) const
bool CMIRIAMResourceObject::isValid ( ) const

Definition at line 182 of file CConstants.cpp.

References C_INVALID_INDEX, mId, and mResource.

Referenced by CBiologicalDescription::clearInvalidEntries(), CReference::clearInvalidEntries(), CRDFNode::setFieldValue(), setId(), and setURI().

183 {
184  // Check whether the resource is known.
185  if (mResource == C_INVALID_INDEX)
186  return false;
187 
188  // Empty IDs are not allowed.
189  if (mId == "")
190  return false;
191 
192  // TODO Check whether the Id matches the regular expression.
193  return true;
194 }
#define C_INVALID_INDEX
Definition: copasi.h:222
bool CMIRIAMResourceObject::isValid ( const std::string &  URI) const

Definition at line 196 of file CConstants.cpp.

References C_INVALID_INDEX, CMIRIAMResources::getMIRIAMResourceIndex(), mpResources, and mResource.

197 {
200  return false;
201 
202  return true;
203 }
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getMIRIAMResourceIndex(const std::string &URI) const
bool CMIRIAMResourceObject::setDisplayName ( const std::string &  displayName)

Definition at line 163 of file CConstants.cpp.

References C_INVALID_INDEX, CMIRIAMResources::getResourceIndexFromDisplayName(), mpResources, and mResource.

Referenced by CMIRIAMResourceObject(), CBiologicalDescription::setResource(), and CReference::setResource().

164 {
166 
167  if (mResource == C_INVALID_INDEX)
168  return false;
169 
170  return true;
171 }
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
#define C_INVALID_INDEX
Definition: copasi.h:222
size_t getResourceIndexFromDisplayName(const std::string &displayName) const
bool CMIRIAMResourceObject::setId ( const std::string &  id)

Definition at line 101 of file CConstants.cpp.

References C_INVALID_INDEX, isValid(), mId, mResource, and trimId().

Referenced by CBiologicalDescription::setId(), and CReference::setId().

102 {
103  mId = trimId(id);
104 
105  // Empty IDs are not allowed.
106  if (mId == "")
107  return false;
108 
109  // Check whether the resource is known.
110  if (mResource == C_INVALID_INDEX)
111  return true;
112 
113  return isValid();
114 }
bool isValid() const
Definition: CConstants.cpp:182
#define C_INVALID_INDEX
Definition: copasi.h:222
static std::string trimId(const std::string &id)
Definition: CConstants.cpp:48
void CMIRIAMResourceObject::setMIRIAMResources ( const CMIRIAMResources pResources)
static

Definition at line 81 of file CConstants.cpp.

References mpResources.

Referenced by CConfigurationFile::elevateChildren(), and CopasiUI3Window::slotUpdateMIRIAMFinished().

82 {
83  mpResources = pResources;
84 }
static const CMIRIAMResources * mpResources
Definition: CConstants.h:73
bool CMIRIAMResourceObject::setNode ( CRDFNode pNode)

Definition at line 150 of file CConstants.cpp.

References CRDFNode::getObject(), CRDFObject::getResource(), mpNode, and setURI().

Referenced by CReference::CReference(), CReference::setId(), and CReference::setResource().

151 {
152  mpNode = pNode;
153 
154  if (mpNode != NULL)
155  return setURI(mpNode->getObject().getResource());
156 
157  return true;
158 }
bool setURI(const std::string &URI)
Definition: CConstants.cpp:119
CRDFObject & getObject()
Definition: CRDFNode.cpp:94
const std::string & getResource() const
Definition: CRDFObject.cpp:94
bool CMIRIAMResourceObject::setURI ( const std::string &  URI)

Definition at line 119 of file CConstants.cpp.

References C_INVALID_INDEX, extractId(), getResource(), isValid(), MCAnnotation, mResource, and CCopasiMessage::WARNING.

Referenced by CReference::clearInvalidEntries(), CMIRIAMResourceObject(), and setNode().

120 {
121  mResource = getResource(URI);
122 
123  if (mResource == C_INVALID_INDEX)
124  {
126  }
127 
128  extractId(URI);
129 
130  return isValid();
131 }
size_t getResource(const std::string &URI)
Definition: CConstants.cpp:23
bool isValid() const
Definition: CConstants.cpp:182
#define C_INVALID_INDEX
Definition: copasi.h:222
#define MCAnnotation
void extractId(const std::string &URI)
Definition: CConstants.cpp:205
std::string CMIRIAMResourceObject::trimId ( const std::string &  id)
staticprivate

Definition at line 48 of file CConstants.cpp.

Referenced by setId().

49 {
50  std::string Id = id;
51 
52  /* Trim leading and trailing whitespaces from the string */
53  std::string::size_type begin = Id.find_first_not_of("\x20\x09\x0d\x0a");
54 
55  if (begin == std::string::npos)
56  {
57  Id = "";
58  }
59  else
60  {
61  std::string::size_type end = id.find_last_not_of("\x20\x09\x0d\x0a");
62 
63  if (end == std::string::npos)
64  Id = id.substr(begin);
65  else
66  Id = id.substr(begin, end - begin + 1);
67  }
68 
69  return Id;
70 }
void CMIRIAMResourceObject::unescapeId ( std::string &  id)
staticprivate

Definition at line 31 of file CConstants.cpp.

References CCopasiXMLInterface::utf8().

Referenced by extractId().

32 {
33  // We have to convert all %[0-9a-fA-F][0-9a-fA-F] character sequences to utf8 characters.
34  std::string::size_type pos;
35 
36  for (pos = 0; pos < id.length(); pos++)
37  if (id[pos] == '%' &&
38  id.find_first_not_of("0123456789abcdefABCDEF", pos + 1) > pos + 2)
39  {
40  char ascii[2];
41  ascii[0] = (unsigned char) strtol(id.substr(pos + 1 , 2).c_str(), NULL, 16);
42  ascii[1] = 0x0;
43  id.replace(pos, 3, CCopasiXMLInterface::utf8(ascii));
44  }
45 }
static std::string utf8(const std::string &str)

Member Data Documentation

std::string CMIRIAMResourceObject::mId
private
CRDFNode* CMIRIAMResourceObject::mpNode
private

Definition at line 81 of file CConstants.h.

Referenced by CMIRIAMResourceObject(), getNode(), and setNode().

const CMIRIAMResources * CMIRIAMResourceObject::mpResources = NULL
staticprivate
size_t CMIRIAMResourceObject::mResource
private

The documentation for this class was generated from the following files: