Skip to content

Commit c5905e1

Browse files
authored
Improve version interface (asmaloney#197)
- fix revision ID - move version interface out of the exception header - add better interface to get ASTM & library versions - deprecate Utilities::getVersions()
1 parent 8938ac8 commit c5905e1

11 files changed

+144
-45
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ target_compile_features( ${PROJECT_NAME}
133133
# Target definitions
134134
target_compile_definitions( E57Format
135135
PRIVATE
136-
REVISION_ID="${revision_id}"
136+
REVISION_ID="${REVISION_ID}"
137137
)
138138

139139
if ( E57_DEBUG )

include/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ target_sources( ${PROJECT_NAME}
88
${CMAKE_CURRENT_LIST_DIR}/E57SimpleData.h
99
${CMAKE_CURRENT_LIST_DIR}/E57SimpleReader.h
1010
${CMAKE_CURRENT_LIST_DIR}/E57SimpleWriter.h
11+
E57Version.h
1112
)
1213

1314
install(

include/E57Exception.h

-3
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,6 @@ namespace e57
332332

333333
namespace Utilities
334334
{
335-
// Get latest version of ASTM standard supported, and library id string
336-
E57_DLL void getVersions( int &astmMajor, int &astmMinor, std::string &libraryId );
337-
338335
E57_DLL std::string errorCodeToString( ErrorCode ecode ) noexcept;
339336
}
340337
}

include/E57Version.h

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#pragma once
2+
// Copyright © 2022 Andy Maloney <[email protected]>
3+
// SPDX-License-Identifier: MIT
4+
5+
/// @file E57Version.h ASTM & libE57Format version information.
6+
7+
#include <string>
8+
9+
#include "E57Export.h"
10+
11+
namespace e57
12+
{
13+
namespace Version
14+
{
15+
/*!
16+
@brief Get the version of the ASTM E57 standard that libE57Format supports.
17+
18+
@returns The version as a string (e.g. "1.0")
19+
*/
20+
E57_DLL std::string astm();
21+
22+
/*!
23+
@brief Get the major version of the ASTM E57 standard that libE57Format supports.
24+
25+
@returns The major version
26+
*/
27+
E57_DLL uint32_t astmMajor();
28+
29+
/*!
30+
@brief Get the minor version of the ASTM E57 standard that libE57Format supports.
31+
32+
@returns The minor version
33+
*/
34+
E57_DLL uint32_t astmMinor();
35+
36+
/*!
37+
@brief Get the version of libE57Format library.
38+
39+
@returns The version as a string (e.g. "E57Format-3.0.0-x86_64-darwin").
40+
*/
41+
E57_DLL std::string library();
42+
43+
/*!
44+
@brief Get the version of ASTM E57 standard that the API implementation supports, and library
45+
id string.
46+
47+
@param [out] astmMajor The major version number of the ASTM E57 standard supported.
48+
@param [out] astmMinor The minor version number of the ASTM E57 standard supported.
49+
@param [out] libraryId A string identifying the implementation of the API.
50+
51+
@details
52+
Since the E57 implementation may be dynamically linked underneath the API, the version string
53+
for the implementation and the ASTM version that it supports can't be determined at
54+
compile-time. This function returns these identifiers from the underlying implementation.
55+
56+
@throw No E57Exceptions.
57+
*/
58+
E57_DLL void get( uint32_t &astmMajor, uint32_t &astmMinor, std::string &libraryId );
59+
}
60+
61+
namespace Utilities
62+
{
63+
/*!
64+
@copydetails Version::get()
65+
@deprecated Will be removed in 4.0. Use Version::get() or other functions in the Version
66+
namespace.
67+
*/
68+
[[deprecated( "Will be removed in 4.0. Use Version::get() or other functions in the Version "
69+
"namespace." )]] E57_DLL void
70+
getVersions( int &astmMajor, int &astmMinor, std::string &libraryId );
71+
}
72+
}

src/E57Version.h src/ASTMVersion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2+
// Copyright © 2022 Andy Maloney <[email protected]>
23
// SPDX-License-Identifier: MIT
3-
// Copyright 2020 Andy Maloney <[email protected]>
44

55
#include <cstdint>
66

src/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
target_sources( E57Format
55
PRIVATE
6+
ASTMVersion.h
67
${CMAKE_CURRENT_LIST_DIR}/BlobNode.cpp
78
${CMAKE_CURRENT_LIST_DIR}/BlobNodeImpl.h
89
${CMAKE_CURRENT_LIST_DIR}/BlobNodeImpl.cpp
@@ -66,7 +67,7 @@ target_sources( E57Format
6667
${CMAKE_CURRENT_LIST_DIR}/E57SimpleData.cpp
6768
${CMAKE_CURRENT_LIST_DIR}/E57SimpleReader.cpp
6869
${CMAKE_CURRENT_LIST_DIR}/E57SimpleWriter.cpp
69-
${CMAKE_CURRENT_LIST_DIR}/E57Version.h
70+
E57Version.cpp
7071
${CMAKE_CURRENT_LIST_DIR}/E57XmlParser.cpp
7172
${CMAKE_CURRENT_LIST_DIR}/E57XmlParser.h
7273
)

src/E57Exception.cpp

-28
Original file line numberDiff line numberDiff line change
@@ -276,34 +276,6 @@ namespace e57
276276

277277
//=====================================================================================
278278

279-
/*!
280-
@brief Get the version of ASTM E57 standard that the API implementation supports, and library id
281-
string.
282-
283-
@param [out] astmMajor The major version number of the ASTM E57 standard supported.
284-
@param [out] astmMinor The minor version number of the ASTM E57 standard supported.
285-
@param [out] libraryId A string identifying the implementation of the API.
286-
287-
@details
288-
Since the E57 implementation may be dynamically linked underneath the API, the version string for
289-
the implementation and the ASTM version that it supports can't be determined at compile-time.
290-
This function returns these identifiers from the underlying implementation.
291-
292-
@throw No E57Exceptions.
293-
*/
294-
void Utilities::getVersions( int &astmMajor, int &astmMinor, std::string &libraryId )
295-
{
296-
// REVISION_ID should be passed from compiler command line
297-
298-
#ifndef REVISION_ID
299-
#error "Need to specify REVISION_ID on command line"
300-
#endif
301-
302-
astmMajor = E57_FORMAT_MAJOR;
303-
astmMinor = E57_FORMAT_MINOR;
304-
libraryId = REVISION_ID;
305-
}
306-
307279
/*!
308280
@brief Get short string description of an E57 ErrorCode.
309281

src/E57Version.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright 2020 Andy Maloney <[email protected]>
3+
4+
#include <sstream>
5+
6+
#include "ASTMVersion.h"
7+
#include "E57Version.h"
8+
9+
namespace e57
10+
{
11+
// REVISION_ID should be passed from compiler command line
12+
#ifndef REVISION_ID
13+
#error "Need to specify REVISION_ID on command line"
14+
#endif
15+
16+
std::string Version::astm()
17+
{
18+
std::ostringstream stringStream;
19+
stringStream << E57_FORMAT_MAJOR << "." << E57_FORMAT_MINOR;
20+
return stringStream.str();
21+
}
22+
23+
uint32_t Version::astmMajor()
24+
{
25+
return E57_FORMAT_MAJOR;
26+
}
27+
28+
uint32_t Version::astmMinor()
29+
{
30+
return E57_FORMAT_MINOR;
31+
}
32+
33+
std::string Version::library()
34+
{
35+
return REVISION_ID;
36+
}
37+
38+
void Version::get( uint32_t &astmMajor, uint32_t &astmMinor, std::string &libraryId )
39+
{
40+
astmMajor = E57_FORMAT_MAJOR;
41+
astmMinor = E57_FORMAT_MINOR;
42+
libraryId = REVISION_ID;
43+
}
44+
45+
namespace Utilities
46+
{
47+
void getVersions( int &astmMajor, int &astmMinor, std::string &libraryId )
48+
{
49+
astmMajor = E57_FORMAT_MAJOR;
50+
astmMinor = E57_FORMAT_MINOR;
51+
libraryId = REVISION_ID;
52+
}
53+
}
54+
55+
}

src/ImageFileImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
*/
2727

2828
#include "ImageFileImpl.h"
29+
#include "ASTMVersion.h"
2930
#include "CheckedFile.h"
30-
#include "E57Version.h"
3131
#include "E57XmlParser.h"
3232
#include "StringFunctions.h"
3333
#include "StructureNodeImpl.h"

src/WriterImpl.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
* DEALINGS IN THE SOFTWARE.
2727
*/
2828

29+
#include <cmath>
30+
2931
#include "WriterImpl.h"
3032

3133
#include "Common.h"
32-
#include <cmath>
34+
#include "E57Version.h"
3335

3436
namespace e57
3537
{
@@ -105,15 +107,9 @@ namespace e57
105107
root_.set( "guid", StringNode( imf_, generateRandomGUID() ) );
106108
}
107109

108-
// Get ASTM version number supported by library, so can write it into file
109-
int astmMajor;
110-
int astmMinor;
111-
ustring libraryId;
112-
Utilities::getVersions( astmMajor, astmMinor, libraryId );
113-
114-
root_.set( "versionMajor", IntegerNode( imf_, astmMajor ) );
115-
root_.set( "versionMinor", IntegerNode( imf_, astmMinor ) );
116-
root_.set( "e57LibraryVersion", StringNode( imf_, libraryId ) );
110+
root_.set( "versionMajor", IntegerNode( imf_, Version::astmMajor() ) );
111+
root_.set( "versionMinor", IntegerNode( imf_, Version::astmMinor() ) );
112+
root_.set( "e57LibraryVersion", StringNode( imf_, Version::library() ) );
117113

118114
// Save a dummy string for coordinate system.
119115
// Really should be a valid WKT string identifying the coordinate reference system (CRS).

test/src/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "gtest/gtest.h"
55

6+
#include "E57Version.h"
7+
68
#include "RandomNum.h"
79
#include "TestData.h"
810

@@ -19,6 +21,9 @@ int main( int argc, char **argv )
1921
::testing::GTEST_FLAG( filter ) = "-*Data.*";
2022
}
2123

24+
std::cout << "e57Format version: " << e57::Version::library() << std::endl;
25+
std::cout << "ASTM version: " << e57::Version::astm() << std::endl;
26+
2227
int result = RUN_ALL_TESTS();
2328

2429
return result;

0 commit comments

Comments
 (0)