1 /**
2 * @file SBaseExtensionPoint.cpp
3 * @brief Implementation of SBaseExtensionPoint
4 * @author Akiya Jouraku
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSBML. Please visit http://sbml.org for more
8 * information about SBML, and the latest version of libSBML.
9 *
10 * Copyright (C) 2020 jointly by the following organizations:
11 * 1. California Institute of Technology, Pasadena, CA, USA
12 * 2. University of Heidelberg, Heidelberg, Germany
13 * 3. University College London, London, UK
14 *
15 * Copyright (C) 2019 jointly by the following organizations:
16 * 1. California Institute of Technology, Pasadena, CA, USA
17 * 2. University of Heidelberg, Heidelberg, Germany
18 *
19 * Copyright (C) 2013-2018 jointly by the following organizations:
20 * 1. California Institute of Technology, Pasadena, CA, USA
21 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22 * 3. University of Heidelberg, Heidelberg, Germany
23 *
24 * Copyright (C) 2009-2013 jointly by the following organizations:
25 * 1. California Institute of Technology, Pasadena, CA, USA
26 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27 *
28 * Copyright (C) 2006-2008 by the California Institute of Technology,
29 * Pasadena, CA, USA
30 *
31 * Copyright (C) 2002-2005 jointly by the following organizations:
32 * 1. California Institute of Technology, Pasadena, CA, USA
33 * 2. Japan Science and Technology Agency, Japan
34 *
35 * This library is free software; you can redistribute it and/or modify it
36 * under the terms of the GNU Lesser General Public License as published by
37 * the Free Software Foundation. A copy of the license agreement is provided
38 * in the file named "LICENSE.txt" included with this software distribution
39 * and also available online as http://sbml.org/software/libsbml/license.html
40 * ------------------------------------------------------------------------ -->
41 */
42
43 #include <sbml/common/common.h>
44 #include <sbml/common/operationReturnValues.h>
45 #include <sbml/extension/SBaseExtensionPoint.h>
46 #include <sbml/SBMLTypeCodes.h>
47
48 LIBSBML_CPP_NAMESPACE_BEGIN
49 #ifdef __cplusplus
50
51 /*
52 * constructor
53 */
SBaseExtensionPoint(const std::string & pkgName,int typeCode)54 SBaseExtensionPoint::SBaseExtensionPoint(const std::string& pkgName, int typeCode)
55 : mPackageName(pkgName)
56 , mTypeCode(typeCode)
57 , mElementName()
58 , mElementOnly(false)
59 {
60 }
61
SBaseExtensionPoint(const std::string & pkgName,int typeCode,const std::string & elementName,bool elementOnly)62 SBaseExtensionPoint::SBaseExtensionPoint(const std::string& pkgName,
63 int typeCode, const std::string& elementName, bool elementOnly)
64 : mPackageName(pkgName)
65 , mTypeCode(typeCode)
66 , mElementName(elementName)
67 , mElementOnly(elementOnly)
68 {
69 }
70
getElementName() const71 const std::string& SBaseExtensionPoint::getElementName() const
72 {
73 return mElementName;
74 }
75
isElementOnly() const76 bool SBaseExtensionPoint::isElementOnly() const
77 {
78 return mElementOnly;
79 }
80
81
~SBaseExtensionPoint()82 SBaseExtensionPoint::~SBaseExtensionPoint()
83 {
84
85 }
86
87
88 /*
89 * copy constructor
90 */
SBaseExtensionPoint(const SBaseExtensionPoint & orig)91 SBaseExtensionPoint::SBaseExtensionPoint(const SBaseExtensionPoint& orig)
92 : mPackageName(orig.mPackageName)
93 , mTypeCode(orig.mTypeCode)
94 , mElementName(orig.mElementName)
95 , mElementOnly(orig.mElementOnly)
96 {
97 }
98
operator =(const SBaseExtensionPoint & rhs)99 SBaseExtensionPoint& SBaseExtensionPoint::operator=(const SBaseExtensionPoint& rhs)
100 {
101 if (&rhs != this)
102 {
103 mPackageName = rhs.mPackageName;
104 mTypeCode = rhs.mTypeCode;
105 mElementName = rhs.mElementName;
106 mElementOnly = rhs.mElementOnly;
107 }
108
109 return *this;
110 }
111
112
113 /*
114 * clone
115 */
116 SBaseExtensionPoint*
clone() const117 SBaseExtensionPoint::clone() const
118 {
119 return new SBaseExtensionPoint(*this);
120 }
121
122
123 const std::string&
getPackageName() const124 SBaseExtensionPoint::getPackageName() const
125 {
126 return mPackageName;
127 }
128
129
130 int
getTypeCode() const131 SBaseExtensionPoint::getTypeCode() const
132 {
133 return mTypeCode;
134 }
135
operator ==(const SBaseExtensionPoint & lhs,const SBaseExtensionPoint & rhs)136 bool operator==(const SBaseExtensionPoint& lhs, const SBaseExtensionPoint& rhs)
137 {
138 if ( (lhs.getTypeCode() == rhs.getTypeCode())
139 && (lhs.getPackageName() == rhs.getPackageName())
140 )
141 {
142 // compare element names if necessary
143 if (lhs.isElementOnly() || rhs.isElementOnly())
144 return lhs.getElementName() == rhs.getElementName();
145
146 return true;
147 }
148
149 if ( (lhs.getTypeCode() == SBML_GENERIC_SBASE )
150 && (lhs.getPackageName() == "all" )
151 )
152 {
153 return true;
154 }
155
156 return false;
157 }
158
159
operator <(const SBaseExtensionPoint & lhs,const SBaseExtensionPoint & rhs)160 bool operator<(const SBaseExtensionPoint& lhs, const SBaseExtensionPoint& rhs)
161 {
162 if ( lhs.getPackageName() == rhs.getPackageName() )
163 {
164 if (lhs.getTypeCode() < rhs.getTypeCode())
165 {
166 return true;
167 }
168 else
169 {
170 return false;
171 }
172 }
173 else if ( lhs.getPackageName() < rhs.getPackageName() )
174 {
175 return true;
176 }
177
178 return false;
179 }
180
181
182 #endif /* __cplusplus */
183 /** @cond doxygenIgnored */
184 LIBSBML_EXTERN
185 SBaseExtensionPoint_t *
SBaseExtensionPoint_create(const char * pkgName,int typeCode)186 SBaseExtensionPoint_create(const char* pkgName, int typeCode)
187 {
188 if (pkgName == NULL) return NULL;
189 return new SBaseExtensionPoint(pkgName, typeCode);
190 }
191
192 LIBSBML_EXTERN
193 int
SBaseExtensionPoint_free(SBaseExtensionPoint_t * extPoint)194 SBaseExtensionPoint_free(SBaseExtensionPoint_t *extPoint)
195 {
196 if (extPoint == NULL) return LIBSBML_INVALID_OBJECT;
197 delete extPoint;
198 return LIBSBML_OPERATION_SUCCESS;
199 }
200
201
202 LIBSBML_EXTERN
203 SBaseExtensionPoint_t *
SBaseExtensionPoint_clone(const SBaseExtensionPoint_t * extPoint)204 SBaseExtensionPoint_clone(const SBaseExtensionPoint_t *extPoint)
205 {
206 if (extPoint == NULL) return NULL;
207 return extPoint->clone();
208 }
209
210 LIBSBML_EXTERN
211 char *
SBaseExtensionPoint_getPackageName(const SBaseExtensionPoint_t * extPoint)212 SBaseExtensionPoint_getPackageName(const SBaseExtensionPoint_t *extPoint)
213 {
214 if (extPoint == NULL) return NULL;
215 return safe_strdup(extPoint->getPackageName().c_str());
216 }
217
218 LIBSBML_EXTERN
219 int
SBaseExtensionPoint_getTypeCode(const SBaseExtensionPoint_t * extPoint)220 SBaseExtensionPoint_getTypeCode(const SBaseExtensionPoint_t *extPoint)
221 {
222 if (extPoint == NULL) return LIBSBML_INVALID_OBJECT;
223 return extPoint->getTypeCode();
224 }
225 /** @endcond */
226
227 LIBSBML_CPP_NAMESPACE_END
228
229