Skip to content

Commit 623a9bf

Browse files
NEW: Add version class
1 parent dd54593 commit 623a9bf

13 files changed

+456
-9
lines changed

documentation/smcore/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
- [Options][doc_options]
66
- [Project][doc_project]
77
- [SMString][doc_smstring]
8+
- [Version][doc_version]
89

910
[doc_about]: ./about.md
1011
[doc_license]: ./license.md
1112
[doc_options]: ./options.md
1213
[doc_project]: ./project.md
1314
[doc_smstring]: ./smstring.md
15+
[doc_version]: ./version.md

documentation/smcore/version.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# The project object
2+
3+
This object contains the program version information.
4+
5+
## Implementation
6+
7+
This is a functionality of `smcore` and located in `smcore/version.*`.
8+
9+
## Internals
10+
11+
### Public API
12+
13+
```c++
14+
namespace smos
15+
{
16+
namespace smcore
17+
{
18+
class Version
19+
{
20+
public:
21+
/**
22+
* @brief Default constructor
23+
*/
24+
Version(void);
25+
26+
/**
27+
* @brief Default destructor
28+
*/
29+
~Version(void);
30+
31+
/**
32+
* @brief Copy constructor
33+
*
34+
* @param versionObject Version to copy data from
35+
*/
36+
Version(const Version &versionObject);
37+
38+
/**
39+
* @brief Assignment operator
40+
*
41+
* @param versionObject
42+
* @return Version& reference to current object
43+
*/
44+
Version &operator=(const Version &versionObject);
45+
46+
/**
47+
* @brief Equal operator
48+
*
49+
* @param versionObject Version to compare with
50+
* @return bool True on equal, otherwise false
51+
*/
52+
bool operator==(const Version &versionObject) const;
53+
54+
/**
55+
* @brief Non equal operator
56+
*
57+
* @param versionObject Version to compare with
58+
* @return bool True on non equal, otherwise false
59+
*/
60+
bool operator!=(const Version &versionObject) const;
61+
62+
/**
63+
* @brief Get version information as string
64+
*
65+
* @return smos::smcore::SMString
66+
*/
67+
smos::smcore::SMString AsString(void) const;
68+
69+
/**
70+
* @brief Set the Version object
71+
*
72+
* @param major Major version information
73+
* @param minor Minor version information
74+
* @param revision Revision version informationi
75+
*/
76+
void SetVersion(const short &major, const short &minor, const short &revision);
77+
};
78+
}
79+
}
80+
81+
```
82+
83+
### Usage
84+
85+
```c++
86+
smos::smcore::Version verObjectSrc;
87+
smos::smcore::Version verObjectDst(verObjectSrc);
88+
smos::smcore::SMString versionSrc = verObjectSrc.AsString();
89+
90+
verObjectSrc.SetVersion(1, 2, 3);
91+
verObjectDst = verObjectSrc;
92+
```
93+
94+
## Possible issues

smcore/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set(SMCORE_INCLUDE
3636
options.h
3737
project.h
3838
smstring.h
39+
version.h
3940
)
4041

4142
set(SMCORE_BODY
@@ -46,6 +47,7 @@ set(SMCORE_BODY
4647
options.cpp
4748
project.cpp
4849
smstring.cpp
50+
version.cpp
4951
)
5052

5153
add_library(smcore STATIC

smcore/factory.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace smos
3030
{
3131
namespace smcore
3232
{
33-
3433
class Factory
3534
{
3635
public:

smcore/license.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
5353
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
5454
DEALINGS IN THE SOFTWARE.
5555
)~~~~";
56-
5756
return licenseText;
5857
}
5958
}

smcore/project.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,23 @@ namespace smos
108108
/**
109109
* @brief Location of project source code
110110
*/
111-
smos::smcore::SMString m_sDirectory;
111+
smos::smcore::SMString m_Directory;
112112
/**
113113
* @brief Filename of project file
114114
*/
115-
smos::smcore::SMString m_sProjectFileName;
115+
smos::smcore::SMString m_ProjectFileName;
116116
/**
117117
* @brief Location of project file
118118
*/
119-
smos::smcore::SMString m_sProjectFileDirectory;
119+
smos::smcore::SMString m_ProjectFileDirectory;
120120
/**
121121
* @brief Project setting: Include subdirectories yes/no
122122
*/
123-
bool m_fIncludeSubdirectories;
123+
bool m_includeSubdirectories;
124124
/**
125125
* @brief Some options - need more inspection for knowing kind of options and what they tweak
126126
*/
127-
int m_eOptionFlags;
127+
int m_OptionFlags;
128128
/**
129129
* @brief Reference to language object
130130
*/

smcore/smcore.h

-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ namespace smos
2828
{
2929
namespace smcore
3030
{
31-
3231
class SMCORE_EXPORT SMCore
3332
{
3433
public:
3534
SMCore(void);
3635
};
37-
3836
}
3937
}

smcore/version.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//******************************************************************************
2+
// Copyright (C) 1999 Jim Wanner and the SourceMonitor team.
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the "Software"),
6+
// to deal in the Software without restriction, including without limitation
7+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
// and/or sell copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
// DEALINGS IN THE SOFTWARE.
21+
//******************************************************************************
22+
23+
#include "version.h"
24+
#include <sstream>
25+
26+
namespace smos
27+
{
28+
namespace smcore
29+
{
30+
//******************************************************************************
31+
Version::Version(void) : m_major(0), m_minor(0), m_revision(0)
32+
{
33+
}
34+
//******************************************************************************
35+
Version::~Version(void)
36+
{
37+
}
38+
//******************************************************************************
39+
Version::Version(const Version &versionObject)
40+
{
41+
this->m_major = versionObject.m_major;
42+
this->m_minor = versionObject.m_minor;
43+
this->m_revision = versionObject.m_revision;
44+
}
45+
//******************************************************************************
46+
Version &Version::operator=(const Version &versionObject)
47+
{
48+
if (&versionObject != this)
49+
{
50+
this->m_major = versionObject.m_major;
51+
this->m_minor = versionObject.m_minor;
52+
this->m_revision = versionObject.m_revision;
53+
}
54+
return *this;
55+
}
56+
//******************************************************************************
57+
bool Version::operator==(const Version &versionObject) const
58+
{
59+
if (&versionObject == this)
60+
{
61+
return true;
62+
}
63+
bool result = (this->m_major == versionObject.m_major) &&
64+
(this->m_minor == versionObject.m_minor) &&
65+
(this->m_revision == versionObject.m_revision);
66+
return result;
67+
}
68+
//******************************************************************************
69+
bool Version::operator!=(const Version &versionObject) const
70+
{
71+
bool result = !(*this == versionObject);
72+
return result;
73+
}
74+
//******************************************************************************
75+
smos::smcore::SMString Version::AsString(void) const
76+
{
77+
std::stringstream os;
78+
os << this->m_major << "." << this->m_minor << "." << this->m_revision;
79+
80+
smos::smcore::SMString result = os.str();
81+
return result;
82+
}
83+
//******************************************************************************
84+
void Version::SetVersion(const short &major, const short &minor, const short &revision)
85+
{
86+
this->m_major = major;
87+
this->m_minor = minor;
88+
this->m_revision = revision;
89+
}
90+
}
91+
}

smcore/version.h

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//******************************************************************************
2+
// Copyright (C) 1999 Jim Wanner and the SourceMonitor team.
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the "Software"),
6+
// to deal in the Software without restriction, including without limitation
7+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
// and/or sell copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
// DEALINGS IN THE SOFTWARE.
21+
//******************************************************************************
22+
23+
#pragma once
24+
25+
#include "smstring.h"
26+
#include <ctime>
27+
28+
namespace smos
29+
{
30+
namespace smcore
31+
{
32+
class Version
33+
{
34+
public:
35+
/**
36+
* @brief Default constructor
37+
*/
38+
Version(void);
39+
40+
/**
41+
* @brief Default destructor
42+
*/
43+
~Version(void);
44+
45+
/**
46+
* @brief Copy constructor
47+
*
48+
* @param versionObject Version to copy data from
49+
*/
50+
Version(const Version &versionObject);
51+
52+
/**
53+
* @brief Assignment operator
54+
*
55+
* @param versionObject
56+
* @return Version& reference to current object
57+
*/
58+
Version &operator=(const Version &versionObject);
59+
60+
/**
61+
* @brief Equal operator
62+
*
63+
* @param versionObject Version to compare with
64+
* @return bool True on equal, otherwise false
65+
*/
66+
bool operator==(const Version &versionObject) const;
67+
68+
/**
69+
* @brief Non equal operator
70+
*
71+
* @param versionObject Version to compare with
72+
* @return bool True on non equal, otherwise false
73+
*/
74+
bool operator!=(const Version &versionObject) const;
75+
76+
/**
77+
* @brief Get version information as string
78+
*
79+
* @return smos::smcore::SMString
80+
*/
81+
smos::smcore::SMString AsString(void) const;
82+
83+
/**
84+
* @brief Set the Version object
85+
*
86+
* @param major Major version information
87+
* @param minor Minor version information
88+
* @param revision Revision version informationi
89+
*/
90+
void SetVersion(const short &major, const short &minor, const short &revision);
91+
92+
private:
93+
/**
94+
* @brief Major version number
95+
*/
96+
short m_major;
97+
/**
98+
* @brief Minor version number
99+
*/
100+
short m_minor;
101+
/**
102+
* @brief Revision version number
103+
*/
104+
short m_revision;
105+
};
106+
}
107+
}

smtest/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ set(SMTEST_INCLUDE
4545
test_license.h
4646
test_options.h
4747
test_project.h
48+
test_version.h
4849
)
4950

5051
set(PROJECT_SOURCES
@@ -53,6 +54,7 @@ set(PROJECT_SOURCES
5354
test_license.cpp
5455
test_options.cpp
5556
test_project.cpp
57+
test_version.cpp
5658
${SMTEST_INCLUDE}
5759
${SMCORE_INCLUDE}
5860
)

0 commit comments

Comments
 (0)