COPASI API  4.16.103
SBMLReference.cpp
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/SBMLReference.cpp,v $
3  $Revision: 1.2 $
4  $Name: $
5  $Author: shoops $
6  $Date: 2006/04/27 01:31:21 $
7  End CVS Header */
8 
9 // Copyright 2005 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc. and EML Research, gGmbH.
11 // All rights reserved.
12 
13 #include "copasi.h"
14 
15 #include "SBMLReference.h"
16 
17 std::string SBMLReference::NotFound = "";
18 
20  mURL(""),
21  mIdToKey(),
22  mKeyToId()
23 {}
24 
26  mURL(src.mURL),
27  mIdToKey(src.mIdToKey),
28  mKeyToId(src.mKeyToId)
29 {}
30 
32 {}
33 
34 bool SBMLReference::setURL(const std::string & url)
35 {
36  mURL = url;
37  return true;
38 }
39 
40 const std::string & SBMLReference::getURL() const
41  {return mURL;}
42 
43 const std::string & SBMLReference::getSBMLid(const std::string & key) const
44  {
45  const_iterator it = mKeyToId.find(key);
46  if (it != mKeyToId.end())
47  return it->second;
48  else
49  return NotFound;
50  }
51 
52 const std::string & SBMLReference::getCOPASIkey(const std::string & id) const
53  {
54  const_iterator it = mIdToKey.find(id);
55  if (it != mIdToKey.end())
56  return it->second;
57  else
58  return NotFound;
59  }
60 
61 bool SBMLReference::add(const std::string & id, const std::string & key)
62 {
63  if (mIdToKey.find(id) != mIdToKey.end() ||
64  mKeyToId.find(key) != mKeyToId.end()) return false;
65 
66  mIdToKey[id] = key;
67  mKeyToId[key] = id;
68 
69  return true;
70 }
71 
72 bool SBMLReference::removeSBMLid(const std::string & id)
73 {
74  std::map<std::string, std::string>::iterator itId = mIdToKey.find(id);
75  if (itId == mIdToKey.end()) return false;
76 
77  std::map<std::string, std::string>::iterator itKey = mKeyToId.find(itId->second);
78 
79  mIdToKey.erase(itId);
80 
81  if (itKey == mKeyToId.end()) return false;
82 
83  mKeyToId.erase(itKey);
84 
85  return true;
86 }
87 
88 bool SBMLReference::removeCOPASIkey(const std::string & key)
89 {
90  std::map<std::string, std::string>::iterator itKey = mKeyToId.find(key);
91 
92  if (itKey == mKeyToId.end()) return false;
93 
94  std::map<std::string, std::string>::iterator itId = mIdToKey.find(itKey->second);
95 
96  mKeyToId.erase(itKey);
97 
98  if (itId == mIdToKey.end()) return false;
99 
100  mIdToKey.erase(itId);
101 
102  return true;
103 }
104 
106 {return mKeyToId.begin();}
107 
109  {return mKeyToId.end();}
110 
112  {return mIdToKey.begin();}
113 
115  {return mIdToKey.end();}
const_iterator beginCOPASIkey() const
bool add(const std::string &id, const std::string &key)
const_iterator endSBMLid() const
const_iterator beginSBMLid() const
static std::string NotFound
const std::string & getCOPASIkey(const std::string &id) const
bool removeSBMLid(const std::string &id)
bool removeCOPASIkey(const std::string &key)
const std::string & getSBMLid(const std::string &key) const
const_iterator endCOPASIkey() const
std::map< std::string, std::string >::const_iterator const_iterator
Definition: SBMLReference.h:22
const std::string & getURL() const
std::map< std::string, std::string > mIdToKey
std::map< std::string, std::string > mKeyToId
bool setURL(const std::string &url)
std::string mURL