Skip to content

Commit 7ca4939

Browse files
authored
Merge pull request lammps#4542 from akohlmey/add-json-lib
Integrate header-only JSON library
2 parents a7760e8 + 27d8e10 commit 7ca4939

File tree

9 files changed

+24895
-0
lines changed

9 files changed

+24895
-0
lines changed

src/info.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "group.h"
3535
#include "improper.h"
3636
#include "input.h"
37+
#include "json.h"
3738
#include "lmpfftsettings.h"
3839
#include "modify.h"
3940
#include "neighbor.h"
@@ -291,6 +292,7 @@ void Info::command(int narg, char **arg)
291292
utils::print(out,"\nCompiler: {} with {}\nC++ standard: {}\n",
292293
platform::compiler_info(),platform::openmp_standard(),platform::cxx_standard());
293294
fputs(get_fmt_info().c_str(), out);
295+
fputs(get_json_info().c_str(), out);
294296

295297
fputs("\nActive compile time flags:\n\n",out);
296298
if (has_gzip_support()) fputs("-DLAMMPS_GZIP\n",out);
@@ -1320,6 +1322,16 @@ std::string Info::get_fmt_info()
13201322

13211323
/* ---------------------------------------------------------------------- */
13221324

1325+
std::string Info::get_json_info()
1326+
{
1327+
return fmt::format("Embedded JSON class version: {}.{}.{}\n",
1328+
NLOHMANN_JSON_VERSION_MAJOR,
1329+
NLOHMANN_JSON_VERSION_MINOR,
1330+
NLOHMANN_JSON_VERSION_PATCH);
1331+
}
1332+
1333+
/* ---------------------------------------------------------------------- */
1334+
13231335
void Info::get_memory_info(double *meminfo)
13241336
{
13251337
double bytes = 0;

src/info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Info : public Command {
5050
const std::string &);
5151
static std::string get_fft_info();
5252
static std::string get_fmt_info();
53+
static std::string get_json_info();
5354
static bool has_gpu_device();
5455
static std::string get_gpu_device_info();
5556
static std::string get_accelerator_info(const std::string &pkg = "");

src/json.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* -*- c++ -*- ----------------------------------------------------------
2+
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3+
https://www.lammps.org/, Sandia National Laboratories
4+
LAMMPS development team: developers@lammps.org
5+
6+
Copyright (2003) Sandia Corporation. Under the terms of Contract
7+
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8+
certain rights in this software. This software is distributed under
9+
the GNU General Public License.
10+
11+
See the README file in the top-level LAMMPS directory.
12+
------------------------------------------------------------------------- */
13+
14+
#ifndef LMP_JSON_H
15+
#define LMP_JSON_H
16+
17+
// wrapper around including the JSON parsing and writing class
18+
// Do NOT include in any header file
19+
20+
#include "../third_party/nlohmann/json.hpp"
21+
22+
namespace LAMMPS_NS {
23+
using json = ::nlohmann_lmp::json;
24+
}
25+
#endif

src/lammps.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,7 @@ void LAMMPS::print_config(FILE *fp)
14561456
platform::compiler_info(),platform::openmp_standard(),
14571457
platform::cxx_standard());
14581458
fputs(Info::get_fmt_info().c_str(),fp);
1459+
fputs(Info::get_json_info().c_str(),fp);
14591460

14601461
int major,minor;
14611462
std::string infobuf = platform::mpi_info(major,minor);

src/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "input.h"
1818
#include "library.h"
1919

20+
#include "json.h"
21+
2022
#include <cstdlib>
2123
#include <mpi.h>
2224
#include <new>
@@ -75,6 +77,11 @@ int main(int argc, char **argv)
7577
finalize();
7678
MPI_Abort(MPI_COMM_WORLD, 1);
7779
exit(1);
80+
} catch (json::exception &je) {
81+
fprintf(stderr, "\nJSON library error %d: %s\n", je.id, je.what());
82+
finalize();
83+
MPI_Abort(MPI_COMM_WORLD, 1);
84+
exit(1);
7885
} catch (std::bad_alloc &ae) {
7986
fprintf(stderr, "C++ memory allocation failed: %s\n", ae.what());
8087
finalize();

third_party/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder contains copies of third-party software

0 commit comments

Comments
 (0)