Skip to content

Commit 239205b

Browse files
committed
#296: add overload for setAnnotation that does parses rdf conditionally
1 parent 12a8bcf commit 239205b

2 files changed

Lines changed: 143 additions & 12 deletions

File tree

src/sbml/SBase.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,11 +1249,23 @@ SBase::setIdAttribute (const std::string& sid)
12491249
}
12501250
}
12511251

1252+
int
1253+
SBase::setAnnotation(const XMLNode* annotation)
1254+
{
1255+
return SBase::setAnnotation(annotation, true);
1256+
}
1257+
1258+
int
1259+
SBase::setAnnotation(const std::string& annotation)
1260+
{
1261+
return SBase::setAnnotation(annotation, true);
1262+
}
1263+
12521264
/*
12531265
* Sets the annotation of this SBML object to a copy of annotation.
12541266
*/
12551267
int
1256-
SBase::setAnnotation (const XMLNode* annotation)
1268+
SBase::setAnnotation (const XMLNode* annotation, bool parseRdf)
12571269
{
12581270
//
12591271
// (*NOTICE*)
@@ -1274,7 +1286,7 @@ SBase::setAnnotation (const XMLNode* annotation)
12741286
delete mAnnotation;
12751287

12761288
// the annotation is an rdf annotation but the object has no metaid
1277-
if (RDFAnnotationParser::hasRDFAnnotation(annotation) == true
1289+
if (parseRdf && RDFAnnotationParser::hasRDFAnnotation(annotation) == true
12781290
&& (RDFAnnotationParser::hasCVTermRDFAnnotation(annotation) == true
12791291
|| RDFAnnotationParser::hasHistoryRDFAnnotation(annotation) == true)
12801292
&& isSetMetaId() == false)
@@ -1342,7 +1354,7 @@ SBase::setAnnotation (const XMLNode* annotation)
13421354
}
13431355

13441356

1345-
if(mAnnotation != NULL
1357+
if(parseRdf && mAnnotation != NULL
13461358
&& RDFAnnotationParser::hasCVTermRDFAnnotation(mAnnotation))
13471359
{
13481360
// parse mAnnotation (if any) and set mCVTerms
@@ -1351,7 +1363,7 @@ SBase::setAnnotation (const XMLNode* annotation)
13511363
mCVTermsChanged = true;
13521364
}
13531365

1354-
if(getLevel() > 2 && mAnnotation != NULL
1366+
if(parseRdf && getLevel() > 2 && mAnnotation != NULL
13551367
&& RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
13561368
{
13571369
// parse mAnnotation (if any) and set mHistory
@@ -1371,7 +1383,7 @@ SBase::setAnnotation (const XMLNode* annotation)
13711383
* Sets the annotation (by string) of this SBML object to a copy of annotation.
13721384
*/
13731385
int
1374-
SBase::setAnnotation (const std::string& annotation)
1386+
SBase::setAnnotation (const std::string& annotation, bool parseRdf)
13751387
{
13761388

13771389
int success = LIBSBML_OPERATION_FAILED;
@@ -1404,7 +1416,7 @@ SBase::setAnnotation (const std::string& annotation)
14041416

14051417
if(annt_xmln != NULL)
14061418
{
1407-
success = setAnnotation(annt_xmln);
1419+
success = setAnnotation(annt_xmln, parseRdf);
14081420
delete annt_xmln;
14091421
}
14101422
return success;
@@ -4272,13 +4284,21 @@ SBase::getSBMLNamespaces() const
42724284
*/
42734285
char*
42744286
SBase::toSBML ()
4287+
{
4288+
return safe_strdup( toSBMLString().c_str() );
4289+
}
4290+
4291+
/*
4292+
* @return the partial SBML that describes this SBML object.
4293+
*/
4294+
std::string SBase::toSBMLString()
42754295
{
4276-
ostringstream os;
4277-
XMLOutputStream stream(os, "UTF-8", false);
4296+
ostringstream os;
4297+
XMLOutputStream stream(os, "UTF-8", false);
42784298

4279-
write(stream);
4299+
write(stream);
42804300

4281-
return safe_strdup( os.str().c_str() );
4301+
return os.str();
42824302
}
42834303

42844304

src/sbml/SBase.h

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,54 @@ class LIBSBML_EXTERN SBase
12291229
* @see unsetAnnotation()
12301230
*/
12311231
virtual int setAnnotation (const XMLNode* annotation);
1232+
1233+
/**
1234+
* Sets the value of the "annotation" subelement of this SBML object.
1235+
*
1236+
* The content of @p annotation is copied, and any previous content of
1237+
* this object's "annotation" subelement is deleted.
1238+
*
1239+
* Whereas the SBase "notes" subelement is a container for content to be
1240+
* shown directly to humans, the "annotation" element is a container for
1241+
* optional software-generated content @em not meant to be shown to
1242+
* humans. Every object derived from SBase can have its own value for
1243+
* "annotation". The element's content type is <a target="_blank"
1244+
* href="http://www.w3.org/TR/2004/REC-xml-20040204/#elemdecls">XML type
1245+
* "any"</a>, allowing essentially arbitrary well-formed XML data
1246+
* content.
1247+
*
1248+
* SBML places a few restrictions on the organization of the content of
1249+
* annotations; these are intended to help software tools read and write
1250+
* the data as well as help reduce conflicts between annotations added by
1251+
* different tools. Please see the SBML specifications for more details.
1252+
*
1253+
* Call this method will result in any existing content of the
1254+
* "annotation" subelement to be discarded. Unless you have taken steps
1255+
* to first copy and reconstitute any existing annotations into the @p
1256+
* annotation that is about to be assigned, it is likely that performing
1257+
* such wholesale replacement is unfriendly towards other software
1258+
* applications whose annotations are discarded. An alternative may be
1259+
* to use SBase::appendAnnotation(const XMLNode* annotation) or
1260+
* SBase::appendAnnotation(const std::string& annotation).
1261+
*
1262+
* @param annotation an XML structure that is to be used as the new content
1263+
* of the "annotation" subelement of this object.
1264+
*
1265+
* @param parseRdf if true, the annotation will be parsed for RDF content.
1266+
* This should only be set, if the RDF follows the subset described in the
1267+
* SBML specification.
1268+
*
1269+
* @copydetails doc_returns_one_success_code
1270+
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
1271+
*
1272+
* @see getAnnotationString()
1273+
* @see isSetAnnotation()
1274+
* @see setAnnotation(const std::string& annotation)
1275+
* @see appendAnnotation(const XMLNode* annotation)
1276+
* @see appendAnnotation(const std::string& annotation)
1277+
* @see unsetAnnotation()
1278+
*/
1279+
virtual int setAnnotation(const XMLNode* annotation, bool parseRdf);
12321280

12331281

12341282
/**
@@ -1262,6 +1310,55 @@ class LIBSBML_EXTERN SBase
12621310
*
12631311
* @param annotation an XML string that is to be used as the content
12641312
* of the "annotation" subelement of this object.
1313+
*
1314+
* @copydetails doc_returns_success_code
1315+
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
1316+
* @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t}
1317+
*
1318+
* @see getAnnotationString()
1319+
* @see isSetAnnotation()
1320+
* @see setAnnotation(const XMLNode* annotation)
1321+
* @see appendAnnotation(const XMLNode* annotation)
1322+
* @see appendAnnotation(const std::string& annotation)
1323+
* @see unsetAnnotation()
1324+
*/
1325+
virtual int setAnnotation(const std::string& annotation);
1326+
1327+
/**
1328+
* Sets the value of the "annotation" subelement of this SBML object.
1329+
*
1330+
* The content of @p annotation is copied, and any previous content of
1331+
* this object's "annotation" subelement is deleted.
1332+
*
1333+
* Whereas the SBase "notes" subelement is a container for content to be
1334+
* shown directly to humans, the "annotation" element is a container for
1335+
* optional software-generated content @em not meant to be shown to
1336+
* humans. Every object derived from SBase can have its own value for
1337+
* "annotation". The element's content type is <a target="_blank"
1338+
* href="http://www.w3.org/TR/2004/REC-xml-20040204/#elemdecls">XML type
1339+
* "any"</a>, allowing essentially arbitrary well-formed XML data
1340+
* content.
1341+
*
1342+
* SBML places a few restrictions on the organization of the content of
1343+
* annotations; these are intended to help software tools read and write
1344+
* the data as well as help reduce conflicts between annotations added by
1345+
* different tools. Please see the SBML specifications for more details.
1346+
*
1347+
* Call this method will result in any existing content of the
1348+
* "annotation" subelement to be discarded. Unless you have taken steps
1349+
* to first copy and reconstitute any existing annotations into the @p
1350+
* annotation that is about to be assigned, it is likely that performing
1351+
* such wholesale replacement is unfriendly towards other software
1352+
* applications whose annotations are discarded. An alternative may be
1353+
* to use SBase::appendAnnotation(const XMLNode* annotation) or
1354+
* SBase::appendAnnotation(const std::string& annotation).
1355+
*
1356+
* @param annotation an XML string that is to be used as the content
1357+
* of the "annotation" subelement of this object.
1358+
*
1359+
* @param parseRdf if true, the annotation will be parsed for RDF content.
1360+
* This should only be set, if the RDF follows the subset described in the
1361+
* SBML specification.
12651362
*
12661363
* @copydetails doc_returns_success_code
12671364
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
@@ -1274,7 +1371,7 @@ class LIBSBML_EXTERN SBase
12741371
* @see appendAnnotation(const std::string& annotation)
12751372
* @see unsetAnnotation()
12761373
*/
1277-
virtual int setAnnotation (const std::string& annotation);
1374+
virtual int setAnnotation (const std::string& annotation, bool parseRdf);
12781375

12791376

12801377
/**
@@ -2313,7 +2410,9 @@ s.setNotes("<body xmlns='http://www.w3.org/1999/xhtml'><p>here is my note</p></b
23132410

23142411
/**
23152412
* Returns a string consisting of a partial SBML corresponding to just
2316-
* this object.
2413+
* this object.
2414+
*
2415+
* The string is owned by the caller and has to be freed manualy.
23172416
*
23182417
* @return the partial SBML that describes this SBML object.
23192418
*
@@ -2323,6 +2422,18 @@ s.setNotes("<body xmlns='http://www.w3.org/1999/xhtml'><p>here is my note</p></b
23232422
*/
23242423
char* toSBML();
23252424

2425+
/**
2426+
* Returns a string consisting of a partial SBML corresponding to just
2427+
* this object.
2428+
*
2429+
* @return the partial SBML that describes this SBML object.
2430+
*
2431+
* @warning <span class="warning">This is primarily provided for testing
2432+
* and debugging purposes. It may be removed in a future version of
2433+
* libSBML.</span>
2434+
*/
2435+
std::string toSBMLString();
2436+
23262437

23272438
/**
23282439
* Returns this element as an XMLNode.

0 commit comments

Comments
 (0)