Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow model history without creator #313

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions src/sbml/SBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <sbml/util/util.h>

#include <sbml/annotation/RDFAnnotation.h>
#include <sbml/annotation/Date.h>

#include <sbml/KineticLaw.h>
#include <sbml/SBMLError.h>
Expand Down Expand Up @@ -1064,6 +1065,31 @@ SBase::getModelHistory()
return mHistory;
}

Date*
SBase::getCreatedDate() const
{
return (mHistory != NULL) ? mHistory->getCreatedDate() : NULL;
}

Date*
SBase::getCreatedDate()
{
return (mHistory != NULL) ? mHistory->getCreatedDate() : NULL;
}


Date*
SBase::getModifiedDate(unsigned int n)
{
return (mHistory != NULL) ? mHistory->getModifiedDate(n) : NULL;
}

unsigned int
SBase::getNumModifiedDates()
{
return (mHistory != NULL) ? mHistory->getNumModifiedDates() : NULL;
}


/*
* @return @c true if the metaid of this SBML object is set, false
Expand Down Expand Up @@ -1150,6 +1176,22 @@ SBase::isSetModelHistory() const
}


bool
SBase::isSetCreatedDate() const
{
return (mHistory == NULL) ? false : mHistory->isSetCreatedDate();
}



bool
SBase::isSetModifiedDate() const
{
return (mHistory == NULL) ? false : mHistory->isSetModifiedDate();
}



/*
* Sets the metaid field of the given SBML object to a copy of metaid.
*/
Expand Down Expand Up @@ -2310,6 +2352,39 @@ SBase::setModelHistory(ModelHistory * history)
return status;
}

int
SBase::setCreatedDate(Date* date)
{
if (mHistory != NULL)
{
return mHistory->setCreatedDate(date);
}
else
{
mHistory = new ModelHistory();
mHistoryChanged = true;

return mHistory->setCreatedDate(date);

}
}

int
SBase::addModifiedDate(Date* date)
{
if (mHistory != NULL)
{
return mHistory->addModifiedDate(date);
}
else
{
mHistory = new ModelHistory();
mHistoryChanged = true;

return mHistory->addModifiedDate(date);

}
}

/** @cond doxygenLibsbmlInternal */
/*
Expand Down Expand Up @@ -2892,6 +2967,74 @@ SBase::unsetModelHistory()
}


int
SBase::unsetCreatedDate()
{
if (mHistory != NULL && mHistory->isSetCreatedDate())
{
mHistoryChanged = true;
}
else
{
return LIBSBML_UNEXPECTED_ATTRIBUTE;
}

/* ModelHistory is only allowed on Model in L2
* but on any element in L3
*/
if (getLevel() < 3 && getTypeCode() != SBML_MODEL)
{
return LIBSBML_UNEXPECTED_ATTRIBUTE;
}

Date* created = mHistory->getCreatedDate();
delete created;
mHistory->mCreatedDate = NULL;

if (mHistory->isSetCreatedDate() == true)
{
return LIBSBML_OPERATION_FAILED;
}
else
{
return LIBSBML_OPERATION_SUCCESS;
}
}


int
SBase::unsetModifiedDates()
{
if (mHistory != NULL && mHistory->isSetModifiedDate())
{
mHistoryChanged = true;
}
else
{
return LIBSBML_UNEXPECTED_ATTRIBUTE;
}

/* ModelHistory is only allowed on Model in L2
* but on any element in L3
*/
if (getLevel() < 3 && getTypeCode() != SBML_MODEL)
{
return LIBSBML_UNEXPECTED_ATTRIBUTE;
}

List_freeItems(mHistory->getListModifiedDates(), Date_free, Date_t);

if (mHistory->getNumModifiedDates() > 0)
{
return LIBSBML_OPERATION_FAILED;
}
else
{
return LIBSBML_OPERATION_SUCCESS;
}
}


/*
* Returns the BiologicalQualifier associated with this resource,
* an empty string if the resource does not exist.
Expand Down
133 changes: 133 additions & 0 deletions src/sbml/SBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,19 @@ class LIBSBML_EXTERN SBase
ModelHistory* getModelHistory() const;


/**
* Returns the "creation date" portion of the ModelHistory of this object.
*
* @return a Date object representing the creation date stored in
* this ModelHistory object.
*
* @note In SBML Level&nbsp;2, model history annotations were only
* permitted on the Model element. In SBML Level&nbsp;3, they are
* permitted on all SBML components derived from SBase.
*/
Date * getCreatedDate() const;


/**
* Returns the ModelHistory object, if any, attached to this object.
*
Expand All @@ -988,6 +1001,46 @@ class LIBSBML_EXTERN SBase
ModelHistory* getModelHistory();


/**
* Returns the "creation date" portion of the ModelHistory of this object.
*
* @return a Date object representing the creation date stored in
* this ModelHistory object.
*
* @note In SBML Level&nbsp;2, model history annotations were only
* permitted on the Model element. In SBML Level&nbsp;3, they are
* permitted on all SBML components derived from SBase.
*/
Date * getCreatedDate();


/**
* Get the nth Date object in the list of "modified date" values stored
* in the ModelHistory of this object.
*
* In the MIRIAM format for annotations, there can be multiple
* modification dates. The libSBML ModelHistory class supports this by
* storing a list of "modified date" values.
*
* @return the nth Date in the list of ModifiedDates of this
* ModelHistory or @c NULL if no such object exists.
*/
Date* getModifiedDate(unsigned int n);


/**
* Get the number of Date objects in the ModelHistory of this Iobject's list of
* "modified dates".
*
* In the MIRIAM format for annotations, there can be multiple
* modification dates. The libSBML ModelHistory class supports this by
* storing a list of "modified date" values.
*
* @return the number of ModifiedDates in this ModelHistory.
*/
unsigned int getNumModifiedDates();


/**
* Predicate returning @c true if this object's "metaid" attribute is set.
*
Expand Down Expand Up @@ -1163,6 +1216,30 @@ class LIBSBML_EXTERN SBase
bool isSetModelHistory() const;


/**
* Predicate returning @c true if this
* object has a ModelHistory object attached to it and the created date is set
*
* @return @c true if the CreatedDate of the ModelHistory of this object is set,
* @c false otherwise.
*
* @note In SBML Level&nbsp;2, model history annotations were only
* permitted on the Model element. In SBML Level&nbsp;3, they are
* permitted on all SBML components derived from SBase.
*/
bool isSetCreatedDate() const;


/**
* Predicate returning @c true or @c false depending on whether the
* ModelHistory's "modified date" of this object is set.
*
* @return @c true if the modification date value of this ModelHistory
* object is set, @c false otherwise.
*/
bool isSetModifiedDate() const;


/**
* Sets the value of the "id" attribute of this SBML object.
*
Expand Down Expand Up @@ -1697,6 +1774,32 @@ s.setNotes("<body xmlns='http://www.w3.org/1999/xhtml'><p>here is my note</p></b
int setModelHistory(ModelHistory * history);


/**
* Sets the creation date of the ModelHistory of this object.
*
* @param date a Date object representing the date to which the "created
* date" portion of this ModelHistory should be set.
*
* @copydetails doc_returns_success_code
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
* @li @sbmlconstant{LIBSBML_UNEXPECTED_ATTRIBUTE, OperationReturnValues_t}
*/
int setCreatedDate(Date* date);


/**
* Adds a modified date to the ModelHistory of this object.
*
* @param date a Date object representing the date to which the "modified
* date" portion of this ModelHistory should be set.
*
* @copydetails doc_returns_success_code
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
* @li @sbmlconstant{LIBSBML_UNEXPECTED_ATTRIBUTE, OperationReturnValues_t}
*/
int addModifiedDate(Date* date);


/** @cond doxygenLibsbmlInternal */
/**
* Sets the parent SBMLDocument of this SBML object.
Expand Down Expand Up @@ -2018,6 +2121,36 @@ s.setNotes("<body xmlns='http://www.w3.org/1999/xhtml'><p>here is my note</p></b
int unsetModelHistory();


/**
* Unsets the created date of the ModelHistory object attached to this object.
*
* @copydetails doc_returns_success_code
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
* @li @sbmlconstant{LIBSBML_UNEXPECTED_ATTRIBUTE, OperationReturnValues_t}
* @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t}
*
* @note In SBML Level&nbsp;2, model history annotations were only
* permitted on the Model element. In SBML Level&nbsp;3, they are
* permitted on all SBML components derived from SBase.
*/
int unsetCreatedDate();


/**
* Unsets the modified dates of the ModelHistory object attached to this object.
*
* @copydetails doc_returns_success_code
* @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
* @li @sbmlconstant{LIBSBML_UNEXPECTED_ATTRIBUTE, OperationReturnValues_t}
* @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t}
*
* @note In SBML Level&nbsp;2, model history annotations were only
* permitted on the Model element. In SBML Level&nbsp;3, they are
* permitted on all SBML components derived from SBase.
*/
int unsetModifiedDates();


/**
* Returns the MIRIAM <em>biological qualifier</em> associated with the
* given resource.
Expand Down
Loading