Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
VersionInfo.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* VersionInfo.cc (C) 2000-2018 */
9/* */
10/* Information about an object's version. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/String.h"
18
19#include "arcane/utils/VersionInfo.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
32: m_major(0)
33, m_minor(0)
34, m_patch(0)
35{
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
42VersionInfo(int vmajor, int vminor, int vpatch)
43: m_major(vmajor)
44, m_minor(vminor)
45, m_patch(vpatch)
46{
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52static void
53_parseStr(std::istream& istr, int& version)
54{
55 if (!istr.good())
56 return;
57 int z = 0;
58 char buf[2];
59 istr >> z;
60 istr.read(buf, 1);
61 if (z < 0)
62 z = 0;
63 version = z;
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
70VersionInfo(const String& version_str)
71: m_major(0)
72, m_minor(0)
73, m_patch(0)
74{
75 std::istringstream istr(version_str.localstr());
76 _parseStr(istr, m_major);
77 _parseStr(istr, m_minor);
78 _parseStr(istr, m_patch);
79}
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
84void VersionInfo::
85write(std::ostream& o) const
86{
87 o << versionMajor() << '.' << versionMinor() << '.' << versionPatch();
88}
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
94versionAsString() const
95{
96 return String::format("{0}.{1}.{2}", versionMajor(), versionMinor(), versionPatch());
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102std::ostream&
103operator<<(std::ostream& o, const VersionInfo& vi)
104{
105 vi.write(o);
106 return o;
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112} // namespace Arcane
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
Definition String.cc:229
Information about a version.
Definition VersionInfo.h:47
String versionAsString() const
Version number in string format.
int versionMajor() const
Returns the major version number.
Definition VersionInfo.h:65
VersionInfo()
Constructs a null version.
int versionMinor() const
Returns the minor version number.
Definition VersionInfo.h:68
int versionPatch() const
Returns the patch version number.
Definition VersionInfo.h:71
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.