1 /**
2  * \file    addModelHistory.cpp
3  * \brief   adds Model History to a model
4  * \author  Sarah Keating
5  *
6  * <!--------------------------------------------------------------------------
7  * This sample program is distributed under a different license than the rest
8  * of libSBML.  This program uses the open-source MIT license, as follows:
9  *
10  * Copyright (c) 2013-2018 by the California Institute of Technology
11  * (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
12  * and the University of Heidelberg (Germany), with support from the National
13  * Institutes of Health (USA) under grant R01GM070923.  All rights reserved.
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included in
23  * all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  * Neither the name of the California Institute of Technology (Caltech), nor
34  * of the European Bioinformatics Institute (EMBL-EBI), nor of the University
35  * of Heidelberg, nor the names of any contributors, may be used to endorse
36  * or promote products derived from this software without specific prior
37  * written permission.
38  * ------------------------------------------------------------------------ -->
39  */
40 
41 
42 #include <iostream>
43 #include <sbml/SBMLTypes.h>
44 
45 #include <sbml/xml/XMLNode.h>
46 #include <sbml/annotation/ModelHistory.h>
47 using namespace std;
48 LIBSBML_CPP_NAMESPACE_USE
49 
printStatus(std::string message,int status)50 void printStatus(std::string message, int status)
51 {
52 	std::string statusString;
53 	switch(status)
54 	{
55 	case LIBSBML_OPERATION_SUCCESS:
56 		statusString = "succeeded";
57 		break;
58 	case LIBSBML_INVALID_OBJECT:
59 		statusString = "invalid object";
60 		break;
61 	case LIBSBML_OPERATION_FAILED:
62 		statusString = "operation failed";
63 		break;
64 	default:
65 		statusString = "unknown";
66 		break;
67 	}
68 
69 	cout << message << statusString << endl;
70 
71 }
72 
73 int
main(int argc,char * argv[])74 main (int argc, char *argv[])
75 {
76 
77   SBMLDocument* d;
78   unsigned int  errors;
79 
80   if (argc != 3)
81   {
82     cout << endl
83          << "  usage: addModelHistory <input-filename> <output-filename>" << endl
84          << endl;
85     return 2;
86   }
87 
88 
89   d      = readSBML(argv[1]);
90   errors = d->getNumErrors();
91 
92   if (errors > 0)
93   {
94     cout << "Read Error(s):" << endl;
95 	  d->printErrors(cout);
96 
97     cout << "Correct the above and re-run." << endl;
98   }
99   else
100   {
101     ModelHistory * h = new ModelHistory();
102 
103     ModelCreator *c = new ModelCreator();
104     c->setFamilyName("Keating");
105     c->setGivenName("Sarah");
106     c->setEmail("sbml-team@caltech.edu");
107     c->setOrganization("University of Hertfordshire");
108 
109     int status = h->addCreator(c);
110 	printStatus("Status for addCreator: ", status);
111 
112 
113     Date * date = new Date("1999-11-13T06:54:32");
114     Date * date2 = new Date("2007-11-30T06:54:00-02:00");
115 
116     status = h->setCreatedDate(date);
117 	printStatus("Set created date:      ", status);
118 
119     status = h->setModifiedDate(date2);
120 	printStatus("Set modified date:     ", status);
121 
122     status = d->getModel()->setModelHistory(h);
123 	printStatus("Set model history:     ", status);
124 
125     delete h;
126     delete c;
127     delete date;
128     delete date2;
129     writeSBML(d, argv[2]);
130   }
131 
132   delete d;
133   return errors;
134 }
135 
136