types.hpp 4.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/**
 * @file types.hpp
 * @author Noah Kirschmann (noah.kirschmann@mnd.thm.de)
 * @brief This file contains basic types for use throughout libtrainsim.
 * @version 0.4.0
 * @date 2020-10-20
 * 
 * @copyright Copyright (c) 2020
 * 
 */
 
12
#pragma once
13

14
15
16
#include <string>
#include <vector>
#include <sstream>
Noah Kirschmann's avatar
Noah Kirschmann committed
17
18
#include <tuple>
#include <algorithm>
19

20
21
22
23
#undef major
#undef minor
#undef patch

24
/**
25
 * @brief This namespace contains all of libtrainsim.
26
27
 * 
 */
Noah Kirschmann's avatar
Noah Kirschmann committed
28
namespace libtrainsim {
29
30
31
32
    /**
    * @brief This namespace contains all the core components of libtrainsim.
    * 
    */
Noah Kirschmann's avatar
Noah Kirschmann committed
33
34
    namespace core {

35
        /**
Noah Kirschmann's avatar
Noah Kirschmann committed
36
37
38
39
40
         * @brief splits a string into several others
         *
         * @param s the string to be split
         * @param delimiter the character that determines where to split the string
         * @return std::vector<std::string> a vector containing with the split parts of the string.
41
         */
Noah Kirschmann's avatar
Noah Kirschmann committed
42
        std::vector<std::string> split_string(const std::string& s, char delimiter);
43
44

        /**
Noah Kirschmann's avatar
Noah Kirschmann committed
45
46
         * @brief a simple class for version checking
         *
47
         */
Noah Kirschmann's avatar
Noah Kirschmann committed
48
49
        class version {
        public:
Noah Kirschmann's avatar
Noah Kirschmann committed
50
51
52
53
54
55
56
            
            /**
             * @brief The major version number x.y.z
             *
             */
            const std::tuple<uint64_t,uint64_t,uint64_t> Version;
            
Noah Kirschmann's avatar
Noah Kirschmann committed
57
58
59
60
            /**
             * @brief The major version number X.y.z
             *
             */
Noah Kirschmann's avatar
Noah Kirschmann committed
61
62
            uint64_t major() const;
            
Noah Kirschmann's avatar
Noah Kirschmann committed
63
64
65
66
            /**
             * @brief The minor version number x.Y.z
             *
             */
Noah Kirschmann's avatar
Noah Kirschmann committed
67
68
            uint64_t minor() const;
            
Noah Kirschmann's avatar
Noah Kirschmann committed
69
70
71
72
            /**
             * @brief The patch version number x.y.Z
             *
             */
Noah Kirschmann's avatar
Noah Kirschmann committed
73
            uint64_t patch() const;
Noah Kirschmann's avatar
Noah Kirschmann committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

            /**
             * @brief Construct a new version object with given major, minor and patch version number.
             *
             * @param x major
             * @param y minor
             * @param z patch
             */
            version(uint64_t x, uint64_t y, uint64_t z);

            /**
             * @brief Construct a new version object from a given string with the format "x.y.z".
             *
             * @param ver a string in the format manjor.minor.patch
             */
            version(const std::string& ver);
Noah Kirschmann's avatar
Noah Kirschmann committed
90
91
92
93
94
95
            /**
             * @brief Construct a new version object from a given string with the format "x.y.z".
             *
             * @param ver a string in the format manjor.minor.patch
             */
            version(std::tuple<uint64_t,uint64_t,uint64_t> ver);
Noah Kirschmann's avatar
Noah Kirschmann committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

            /**
             * @brief returns the version number as "major.minor.patch".
             *
             * @return std::string The version number as string
             */
            std::string print() const;

            /**
             * @brief three way comparison between two version numbers.
             * positive if v1 > v2
             * 0 if v1 == v2
             * negative if v1 < v2
             *
             * @param v1 the first version
             * @param v2 the second version
             * @return int the result of the comparison
             */
            static int compare(const version& v1, const version& v2) {
Noah Kirschmann's avatar
Noah Kirschmann committed
115
116
                if (v1.Version > v2.Version) { return 1; }
                if (v1.Version < v2.Version) { return -1; }
Noah Kirschmann's avatar
Noah Kirschmann committed
117
118
119

                return 0;
            };
Noah Kirschmann's avatar
Noah Kirschmann committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
            
            /*
             * @brief Compare two versions.
             */
            bool operator>(const version& other) const;
            
            /*
             * @brief Compare two versions.
             */
            bool operator<(const version& other) const;
            
            /*
             * @brief Compare two versions.
             */
            bool operator>=(const version& other) const;
            
            /*
             * @brief Compare two versions.
             */
            bool operator<=(const version& other) const;
            
            /*
             * @brief Compare two versions.
             */
            bool operator==(const version& other) const;
Noah Kirschmann's avatar
Noah Kirschmann committed
145
        };
146
147

        /**
Noah Kirschmann's avatar
Noah Kirschmann committed
148
149
         * @brief the current version of the libtrainsim
         *
150
         */
151
        const version lib_version(0,10,0);
Noah Kirschmann's avatar
Noah Kirschmann committed
152

153
        /**
Noah Kirschmann's avatar
Noah Kirschmann committed
154
155
         * @brief the current version of the json formats
         *
156
         */
noasakurajin's avatar
noasakurajin committed
157
        const version format_version(0,7,0);
Noah Kirschmann's avatar
Noah Kirschmann committed
158

159
    }
160
}