~vbursian/research-assistant/intervers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
////////////////////////////////////////////////////////////////////////////////
/*! @file Version.cpp   Source code version identification.
- Part of RANet - Research Assistant Net Library.
- Copyright(C) 2010-2015, Viktor E. Bursian, St.Petersburg, Russia.
                          Viktor.Bursian@mail.ioffe.ru
*///////////////////////////////////////////////////////////////////////////////
#include "Version.h"
namespace RA {
//------------------------------------------------------------------------------

namespace RANet {

  sVersion const              Version (RA_VERS_MAJOR
                                      ,RA_VERS_MINOR
                                      ,ZAKAVYCH(RA_VERS_PATCH)
                                      ,__DATE__
                                      );
}

//----------------------------------------------------------------- sVersion ---

sVersion::sVersion (sString  text)
    :Major(-9),Minor(-9),Patch(-9),Stage(-9)
{
  size_t                      P;
  sString                     PatchAndStage;
  text >> Major;
  P = text.Pos(".");
  if( P < text.Length() ){
    text = text.Tail(P+1);
    text >> Minor;
    P = text.Pos(".");
    if( P < text.Length() ){
      text = text.Tail(P+1);
      P = text.Pos(" (");
      if( P == text.Length() ){
        PatchAndStage = text;
      }else{
        PatchAndStage = text.Substr(0,P);
      }
    }
  }
  ParsePatchAndStage(PatchAndStage);
}


sVersion::sVersion (int        major_part
                   ,int        minor_part
                   ,rcsString  patch_and_stage
                   ,rcsString  build_date)
    :Major(major_part),Minor(minor_part),Patch(-9),Stage(-9)
    ,BuildDate(build_date)
{
  ParsePatchAndStage(patch_and_stage);
}


void  sVersion::ParsePatchAndStage (rcsString  patch_and_stage)
{
  sString                     S1(patch_and_stage);
  size_t                      P = patch_and_stage.Pos("-");
  if( P == patch_and_stage.Length() ){
    Stage = 0;
  }else{
    S1 = patch_and_stage.Substr(0,P);
    sString                     S2(patch_and_stage.Tail(P+1));
    if( S2 == "alpha" ){
      Stage = -2;
    }else if( S2 == "beta" ){
      Stage = -1;
    }
  }
  sString                     T;
  sString(S1) >> Patch;
  T << Patch;
  if( T != S1 )  Patch = -9;
}


sVersion::sVersion ()
    :Major(-9),Minor(-9),Patch(-9),Stage(-9)
{
}


sVersion::sVersion (int  major_part
                   ,int  minor_part)
    :Major(major_part),Minor(minor_part),Patch(-9),Stage(-9)
{
}


sVersion::sVersion (int  major_part
                   ,int  minor_part
                   ,int  patch_part
                   ,int  stage_part)
    :Major(major_part),Minor(minor_part),Patch(patch_part),Stage(stage_part)
{
}


sVersion::sVersion (rcsVersion  other)
    :Major(other.Major),Minor(other.Minor),Patch(other.Patch)
    ,Stage(other.Stage),BuildDate(other.BuildDate)
{
}


rsVersion  sVersion::operator = (rcsVersion  other)
{
  Major = other.Major;
  Minor = other.Minor;
  Patch = other.Patch;
  Stage = other.Stage;
  BuildDate = other.BuildDate;
  return *this;
}


sString  sVersion::Text () const
{
  sString                     V;
  if( ! IsValid() ){
    V = "invalid version";
  }else{
    V << Major;
    V += ".";
    V << Minor;
    if( Patch >= 0 ){
      V += ".";
      V << Patch;
      switch( Stage ){
        case -2:
          V += "-alpha";
          break;
        case -1:
          V += "-beta";
          break;
        case 0:
          break;
        default:
          V += "-???";
          break;
      }
    }
    if( ! BuildDate.Empty() ){
      V += " (";
      V += BuildDate;
      V += ")";
    }
  }
  return V;
}


bool  sVersion::IsValid () const
{
  return  (Major >= 0) && (Minor >= 0);
}


bool  sVersion::IsValidAndNumeric () const
{
  return  (Major >= 0) && (Minor >= 0) && (Patch >= 0) && (Stage == 0);
}


bool  sVersion::operator == (rcsVersion  V) const
{
  return  (Major == V.Major) && (Minor == V.Minor) && (Patch == V.Patch)
                                                   && (Stage == V.Stage);
}


bool  sVersion::operator < (rcsVersion  V) const
{
  return   (Major < V.Major)
      || ( (Major == V.Major) && (Minor < V.Minor) )
      || ( (Major == V.Major) && (Minor == V.Minor) && (Patch < V.Patch) )
      || ( (Major == V.Major) && (Minor == V.Minor) && (Patch == V.Patch)
                                                    && (Stage < V.Stage) )
      ;
}


bool  sVersion::operator <= (rcsVersion  V) const
{
  return  operator < (V) || operator == (V);
}


bool  sVersion::operator > (rcsVersion  V) const
{
  return   (Major > V.Major)
      || ( (Major == V.Major) && (Minor > V.Minor) )
      || ( (Major == V.Major) && (Minor == V.Minor) && (Patch > V.Patch) )
      || ( (Major == V.Major) && (Minor == V.Minor) && (Patch == V.Patch)
                                                    && (Stage > V.Stage) )
      ;
}


bool  sVersion::operator >= (rcsVersion  V) const
{
  return  operator > (V) || operator == (V);
}

//------------------------------------------------------------------------------
} //namespace RA