Skip to content

Commit 46a9267

Browse files
committed
IO: use Boost library for reading/writing configuration files
1 parent e9eb1d1 commit 46a9267

16 files changed

+468
-956
lines changed

CMakeLists.txt

+9-37
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ if (BITPIT_ENABLE_MPI)
593593
endif()
594594
set(OPERATORS_EXTERNAL_DEPS "")
595595
set(CONTAINERS_EXTERNAL_DEPS "")
596-
set(IO_EXTERNAL_DEPS "LibXml2;RapidJSON")
596+
set(IO_EXTERNAL_DEPS "Boost")
597597
set(COMMUNICATIONS_EXTERNAL_DEPS "MPI")
598598
set(LA_EXTERNAL_DEPS "PETSc")
599599
set(SA_EXTERNAL_DEPS "")
@@ -831,39 +831,6 @@ if (${_LAPACKE_index} GREATER -1)
831831
endif()
832832
unset(_LAPACKE_index)
833833

834-
list(FIND EXTERNAL_DEPS "LibXml2" _LibXml2_index)
835-
if (${_LibXml2_index} GREATER -1)
836-
find_package(LibXml2 REQUIRED)
837-
838-
list (INSERT BITPIT_EXTERNAL_DEPENDENCIES 0 "LibXml2")
839-
list (INSERT BITPIT_EXTERNAL_VARIABLES_LIBRARIES 0 "LIBXML2_LIBRARIES")
840-
list (INSERT BITPIT_EXTERNAL_VARIABLES_INCLUDE_DIRS 0 "LIBXML2_INCLUDE_DIR")
841-
endif()
842-
unset(_LibXml2_index)
843-
844-
list(FIND EXTERNAL_DEPS "RapidJSON" _RapidJSON_index)
845-
if (${_RapidJSON_index} GREATER -1)
846-
find_package(RapidJSON 1.1.0 QUIET)
847-
mark_as_advanced(RapidJSON_DIR)
848-
849-
if (RapidJSON_FOUND)
850-
# RapidJSON library has been found
851-
target_compile_definitions(${BITPIT_LIBRARY} PUBLIC "BITPIT_ENABLE_RAPIDJSON=1")
852-
853-
list (INSERT BITPIT_EXTERNAL_DEPENDENCIES 0 "RapidJSON")
854-
list (INSERT BITPIT_EXTERNAL_VARIABLES_INCLUDE_DIRS 0 "RAPIDJSON_INCLUDE_DIRS")
855-
856-
# Activate std::string RapidJSON compliancy
857-
target_compile_definitions(${BITPIT_LIBRARY} PUBLIC "RAPIDJSON_HAS_STDSTRING=1")
858-
else()
859-
# RapidJSON library has not been found
860-
target_compile_definitions(${BITPIT_LIBRARY} PUBLIC "BITPIT_ENABLE_RAPIDJSON=0")
861-
862-
message(STATUS "RapidJSON library not found, JSON support will be disabled.")
863-
endif()
864-
endif()
865-
unset(_RapidJSON_index)
866-
867834
list(FIND EXTERNAL_DEPS "PETSc" _PETSc_index)
868835
if (${_PETSc_index} GREATER -1)
869836
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/PETSc/cmake")
@@ -890,15 +857,20 @@ if (${_PETSc_index} GREATER -1)
890857
endif()
891858
unset(_PETSc_index)
892859

893-
list(FIND EXTERNAL_DEPS "BoostTest" _BoostTest_index)
894-
if (${_BoostTest_index} GREATER -1)
860+
list(FIND EXTERNAL_DEPS "Boost" _Boost_index)
861+
if (${_Boost_index} GREATER -1)
895862
set(BOOST_COMPONENTS "")
863+
list(FIND EXTERNAL_DEPS "BoostTest" _BoostTest_index)
896864
if(${_BoostTest_index} GREATER -1)
897865
LIST(APPEND BOOST_COMPONENTS "unit_test_framework")
898866
endif()
899867
string (REPLACE ";" " " BOOST_COMPONENTS_STRING "${BOOST_COMPONENTS}")
900868

901-
FIND_PACKAGE(Boost 1.40 COMPONENTS "${BOOST_COMPONENTS_STRING}" REQUIRED)
869+
if ("${BOOST_COMPONENTS}" STREQUAL "")
870+
FIND_PACKAGE(Boost 1.40 REQUIRED)
871+
else ()
872+
FIND_PACKAGE(Boost 1.40 COMPONENTS "${BOOST_COMPONENTS_STRING}" REQUIRED)
873+
endif ()
902874

903875
list (INSERT BITPIT_EXTERNAL_DEPENDENCIES 0 "Boost")
904876
list (INSERT BITPIT_EXTERNAL_VARIABLES_LIBRARIES 0 "Boost_LIBRARIES")

INSTALL.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ bitpit depends on
99
* (optionally) MPI implementation. It has been tested with OpenMPI >= 1.6.5.
1010

1111
Some additional dependencies are required for building specific modules
12-
* libxml2 and its development headers are needed when compiling the 'IO'
12+
* boost and its development headers are needed when compiling the 'IO'
1313
module (please note that the 'IO' module is a dependecies for many other
1414
bitpit modules, the only modules that do not depend on 'IO' are the low
15-
level modules like 'operators', 'containers', 'LA', and 'SA'). Moreover,
16-
json support is automatically enabled if RapidJSON (version 1.1.0) libraries
17-
are installed on the system (https://github.com/Tencent/rapidjson): this is
18-
a completely optional requirement, IO module will compile and work fine
19-
with the only xml support too;
15+
level modules like 'operators', 'containers', 'LA', and 'SA').
2016
* blas, lapack, and lapacke are needed when compiling 'CG', 'RBF', and 'POD'
2117
modules.
2218

README_WINDOWS.md

-18
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ This is a short guide to set a bitpit compliant 64bit Windows environment using
1717
- mingw-w64-x86_64-toolchain
1818
- mingw-w64-x86_64-lapack
1919
- mingw-w64-x86_64-msmpi
20-
- mingw-w64-x86_64-libxml2
2120
- mingw-w64-x86_64-cmake
2221
- mingw-w64-x86_64-qt5 (optional, but needed to run cmake-gui. Consider 1.22 GB to install it.)
2322
- mingw-w64-x86_64-doxygen (to generate Doxygen documentation)
2423
- mingw-w64-x86_64-graphviz (to generate Doxygen documentation)
25-
- mingw-w64-x86_64-rapidjson (to enable JSON I/O support on IO module)
2624

2725
- <B>Microsoft MPI</B>: MSMpiSetup.exe or msmpisdk.msi (downloadable for free from https://www.microsoft.com/ searching for "MicrosoftMPI v x.x.x". Here the exact version x.x.x must be compliant with the version of MinGW64 package mingw-w64-x86_64-msmpi. See MSMPI section in procedure chapter for details)
2826

@@ -200,22 +198,6 @@ user@machine MINGW64 ~
200198
> pacman -S mingw-w64-x86_64-lapack
201199
```
202200
203-
**__LIBMXL2__**
204-
205-
Install *libxml2* with:
206-
```bash
207-
user@machine MINGW64 ~
208-
> pacman -S mingw-w64-x86_64-libxml2
209-
```
210-
211-
**__RAPIDJSON__**
212-
213-
If JSON support on IO module is required, install *rapidjson* with:
214-
```bash
215-
user@machine MINGW64 ~
216-
> pacman -S mingw-w64-x86_64-rapidjson
217-
```
218-
219201
**__PETSc__**
220202
221203
_PETSc_ can be installed on the MSYS2/MinGW64 environment in two ways:

THIRDPARTIES.md

-46
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,6 @@
8181
```
8282
</details>
8383

84-
## libxml2
85-
<details>
86-
<summary>See License</summary>
87-
88-
```
89-
Except where otherwise noted in the source code (e.g. the files hash.c,
90-
list.c and the trio files, which are covered by a similar licence but
91-
with different Copyright notices) all the files are:
92-
93-
Copyright (C) 1998-2012 Daniel Veillard. All Rights Reserved.
94-
95-
Permission is hereby granted, free of charge, to any person obtaining a copy
96-
of this software and associated documentation files (the "Software"), to deal
97-
in the Software without restriction, including without limitation the rights
98-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99-
copies of the Software, and to permit persons to whom the Software is fur-
100-
nished to do so, subject to the following conditions:
101-
102-
The above copyright notice and this permission notice shall be included in
103-
all copies or substantial portions of the Software.
104-
105-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
107-
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
111-
THE SOFTWARE.
112-
```
113-
</details>
114-
11584
## METIS
11685
<details>
11786
<summary>See License</summary>
@@ -252,18 +221,3 @@
252221
This license DOES NOT apply to any software that may be obtained via the download-package option of the PETSc configuration. Each of those packages are covered by their own licenses.
253222
```
254223
</details>
255-
256-
## RAPIDJSON
257-
<details>
258-
<summary>See License</summary>
259-
260-
```
261-
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
262-
263-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
264-
265-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
266-
267-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
268-
```
269-
</details>

environments/ubuntu/Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ RUN sed -i "s/htt[p|ps]:\/\/archive.ubuntu.com\/ubuntu\//mirror:\/\/mirrors.ubun
1111
liblapack-dev \
1212
liblapacke-dev \
1313
mpich \
14-
libxml2-dev \
1514
libmetis-dev \
1615
git \
1716
wget \
18-
python3 \
19-
rapidjson-dev
17+
python3
2018

2119
FROM bitpit-ubuntu-base AS bitpit-ubuntu-mpi
2220
LABEL stage=bitpit-ubuntu-mpi

src/IO/configuration.cpp

+21-24
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424

2525

2626
#include "configuration.hpp"
27-
#include "configuration_XML.hpp"
28-
29-
#if BITPIT_ENABLE_RAPIDJSON
30-
#include "configuration_JSON.hpp"
31-
#endif
27+
#include "configuration_tree.hpp"
3228

3329
#include <stringUtils.hpp>
3430

@@ -152,8 +148,7 @@ void ConfigParser::reset(const std::string &root, int version, bool multiSection
152148
/*!
153149
Read the specified configuration file.
154150
155-
Configuration file can be either XML or JSON files (if JSON support was
156-
found at compile time).
151+
Configuration can be read either from XML or JSON files.
157152
158153
\param filename is the filename of the configuration file
159154
\param append controls if the configuration file will be appended to the
@@ -175,23 +170,27 @@ void ConfigParser::read(const std::string &filename, bool append)
175170
extension = utils::string::trim(extension);
176171
}
177172

173+
config::FileFormat fileFormat;
178174
if (extension == "xml" || extension == "XML") {
179-
config::XML::readConfiguration(filename, m_root, m_checkVersion, m_version, this);
180-
#if BITPIT_ENABLE_RAPIDJSON
175+
fileFormat = config::FILE_FORMAT_XML;
181176
} else if (extension == "json" || extension == "JSON") {
182-
config::JSON::readConfiguration(filename, this);
183-
#endif
177+
fileFormat = config::FILE_FORMAT_JSON;
184178
} else {
185179
throw std::runtime_error("ConfigParser::read - Unsupported file format");
186180
}
181+
182+
bool checkFileVersion = false;
183+
if (fileFormat == config::FILE_FORMAT_XML) {
184+
checkFileVersion = m_checkVersion;
185+
}
186+
187+
config::tree::readConfiguration(filename, fileFormat, m_root, checkFileVersion, m_version, this);
187188
}
188189

189190
/*!
190191
Write the configuration to the specified file.
191192
192-
Configuration file can be either XML or JSON files (if JSON support was
193-
found at compile time).
194-
193+
Configuration can be written either to XML or JSON files.
195194
196195
\param filename is the filename where the configuration will be written to
197196
*/
@@ -205,16 +204,16 @@ void ConfigParser::write(const std::string &filename) const
205204
extension = utils::string::trim(extension);
206205
}
207206

207+
config::FileFormat fileFormat;
208208
if (extension == "xml" || extension == "XML") {
209-
config::XML::writeConfiguration(filename, m_root, m_version, this);
210-
#if BITPIT_ENABLE_RAPIDJSON
209+
fileFormat = config::FILE_FORMAT_XML;
211210
} else if (extension == "json" || extension == "JSON") {
212-
bool prettify = true;
213-
config::JSON::writeConfiguration(filename, this, prettify);
214-
#endif
211+
fileFormat = config::FILE_FORMAT_JSON;
215212
} else {
216-
throw std::runtime_error("ConfigParser::write - Unsupported file format");
213+
throw std::runtime_error("ConfigParser::read - Unsupported file format");
217214
}
215+
216+
config::tree::writeConfiguration(filename, fileFormat, m_root, m_version, this);
218217
}
219218

220219
/*!
@@ -332,8 +331,7 @@ namespace config {
332331
/*!
333332
Read the specified configuration file.
334333
335-
Configuration file can be either XML or JSON files (if JSON support was
336-
found at compile time).
334+
Configuration can be read either from XML or JSON files.
337335
338336
\param filename is the filename of the configuration file
339337
\param append controls if the configuration file will be appended to the
@@ -348,8 +346,7 @@ namespace config {
348346
/*!
349347
Write the configuration to the specified file.
350348
351-
Configuration file can be either XML or JSON files (if JSON support was
352-
found at compile time).
349+
Configuration can be written either to XML or JSON files.
353350
354351
\param filename is the filename where the configuration will be written to
355352
*/

src/IO/configuration.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <memory>
2828
#include <string>
29-
#include <unordered_map>
3029

3130
#include "configuration_config.hpp"
3231

0 commit comments

Comments
 (0)