COPASI API  4.16.103
CVersion.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CVersion
17  *
18  * (C) Pedro Mendes 2001
19  */
20 #include <sstream>
21 
22 #include "copasi.h"
23 
24 #include "CVersion.h"
25 #include "utility.h"
26 #include "CopasiVersion.h"
27 
28 // initialize the global version instance
29 // static
36 
38  C_INT32 minor,
39  C_INT32 build,
40  const bool & sourcesModified,
41  const std::string & comment,
42  const std::string & creator):
43  mMajor(major),
44  mMinor(minor),
45  mBuild(build),
46  mSourcesModified(sourcesModified),
47  mComment(comment),
48  mCreator(creator),
49  mVersion(""),
50  mCompatible()
51 {
53  int length = sizeof(Compatible) / sizeof(Compatible[0]);
54  C_INT32 * pCompatible = Compatible;
55 
56  for (int count = 0; count < length && *pCompatible != mBuild; pCompatible++, count++)
57  {
58  mCompatible.insert(*pCompatible);
59  }
60 
61  mCompatible.insert(mBuild);
62 
63  setString();
64 }
65 
67  mMajor(0),
68  mMinor(0),
69  mBuild(0),
70  mSourcesModified(false),
71  mComment(""),
72  mCreator(""),
73  mVersion(""),
74  mCompatible()
75 {
76  setString();
77 }
78 
80 {}
81 
82 bool CVersion::isCompatible(const CVersion & version) const
83 {
84  if (mCompatible.empty())
85  {
86  if (mMajor > version.mMajor) return false;
87 
88  if (mMinor > version.mMinor) return false;
89 
90  if (mBuild >= version.mBuild) return false;
91 
92  return true;
93  }
94 
95  if (version.mBuild < *mCompatible.begin()) return true;
96 
97  if (mCompatible.find(version.mBuild) != mCompatible.end()) return true;
98 
99  return false;
100 }
101 
102 void CVersion::setVersion(const C_INT32 & major,
103  const C_INT32 & minor,
104  const C_INT32 & devel,
105  const bool & sourcesModified,
106  const std::string & comment,
107  const std::string & creator)
108 {
109  mMajor = major;
110  mMinor = minor;
111  mBuild = devel;
112  mSourcesModified = sourcesModified;
113  mComment = comment;
114  mCreator = creator;
115 
116  setString();
117 }
118 
120 {
121  return mMajor;
122 }
123 
125 {
126  return mMinor;
127 }
128 
130 {
131  return mBuild;
132 }
133 
134 const bool & CVersion::isSourceModified() const
135 {
136  return mSourcesModified;
137 }
138 
139 const std::string & CVersion::getVersion() const
140 {
141  return mVersion;
142 }
143 
145 {
146 #ifdef COPASI_DEBUG
147  mComment = "Debug";
148 #endif
149 
150  std::stringstream Build;
151  Build << mBuild;
152 
153  if (mSourcesModified)
154  {
155  Build << "+";
156  }
157 
158  if (mComment == "stable")
159  mVersion = StringPrint("%d.%d (Build %s)", mMajor, mMinor, Build.str().c_str());
160  else if (mComment != "")
161  mVersion = StringPrint("%d.%d.%s (%s)", mMajor, mMinor, Build.str().c_str(), mComment.c_str());
162  else
163  mVersion = StringPrint("%d.%d.%s (Source)", mMajor, mMinor, Build.str().c_str());
164 }
void setString()
Definition: CVersion.cpp:144
std::string mVersion
Definition: CVersion.h:69
C_INT32 mMinor
Definition: CVersion.h:42
std::string mCreator
Definition: CVersion.h:64
CVersion()
Definition: CVersion.cpp:66
C_INT32 mBuild
Definition: CVersion.h:47
const bool & isSourceModified() const
Definition: CVersion.cpp:134
bool isCompatible(const CVersion &version) const
Definition: CVersion.cpp:82
C_INT32 getVersionMajor() const
Definition: CVersion.cpp:119
void setVersion(const C_INT32 &major, const C_INT32 &minor, const C_INT32 &devel, const bool &sourcesModified, const std::string &comment="", const std::string &creator="")
Definition: CVersion.cpp:102
~CVersion()
Definition: CVersion.cpp:79
C_INT32 mMajor
Definition: CVersion.h:36
#define C_INT32
Definition: copasi.h:90
std::set< C_INT32 > mCompatible
Definition: CVersion.h:74
#define COPASI_VERSION_BUILD
Definition: CopasiVersion.h:11
#define COPASI_VERSION_MODIFIED
Definition: CopasiVersion.h:12
#define COPASI_VERSION_CREATOR
Definition: CopasiVersion.h:15
#define COPASI_VERSION_MINOR
Definition: CopasiVersion.h:10
#define COPASI_VERSION_MAJOR
Definition: CopasiVersion.h:9
#define COPASI_VERSION_COMPATIBILITY
Definition: CopasiVersion.h:13
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
C_INT32 getVersionMinor() const
Definition: CVersion.cpp:124
C_INT32 getVersionDevel() const
Definition: CVersion.cpp:129
const std::string & getVersion() const
Definition: CVersion.cpp:139
#define COPASI_VERSION_COMMENT
Definition: CopasiVersion.h:14
std::string mComment
Definition: CVersion.h:58
bool mSourcesModified
Definition: CVersion.h:53
static const CVersion VERSION
Definition: CVersion.h:164