<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
Authors:
<NAME> <<EMAIL>>

Maintainers:
Currently maintained by the authors.

This file is part of the util library used by models created at the Institute of
Landscape Systems Analysis at the ZALF.
Copyright (C) Leibniz Centre for Agricultural Landscape Research (ZALF)
*/

#ifndef JSON11_HELPER_H_
#define JSON11_HELPER_H_

#include <string>
#include <functional>
#include <initializer_list>
#include <iostream>

#include "json11/json11.hpp"

#include "tools/date.h"
#include "tools/helper.h"

namespace Tools
{
  template<typename T>
  T identity(T t){ return t; }

  struct Json11Serializable
  {
    virtual Errors merge(json11::Json j) = 0;

    virtual json11::Json to_json() const = 0;

    virtual std::string toString() const { return to_json().dump(); }
  };

  //-------------------------------------------

  typedef json11::Json::array J11Array;
  typedef json11::Json::object J11Object;

  template<class Collection>
  J11Array toPrimJsonArray(const Collection& col)
  {
    std::vector<json11::Json> js;
    for(auto v : col)
      js.push_back(v);
    return js;<commit_msg>make Json11Serializable work with monica dll<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
Authors:
<NAME> <<EMAIL>>

Maintainers:
Currently maintained by the authors.

This file is part of the util library used by models created at the Institute of
Landscape Systems Analysis at the ZALF.
Copyright (C) Leibniz Centre for Agricultural Landscape Research (ZALF)
*/

#ifndef JSON11_HELPER_H_
#define JSON11_HELPER_H_

#include <string>
#include <functional>
#include <initializer_list>
#include <iostream>

#include "json11/json11.hpp"

#include "tools/date.h"
#include "tools/helper.h"

#ifdef DLL_EXPORTS
#define TOOLS_API __declspec(dllexport)
#else
#define TOOLS_API __declspec(dllimport)
#endif

namespace Tools
{
  template<typename T>
  T identity(T t){ return t; }

  struct TOOLS_API Json11Serializable
  {
    virtual Errors merge(json11::Json j) = 0;

    virtual json11::Json to_json() const = 0;

    virtual std::string toString() const { return to_json().dump(); }
  };

  //-------------------------------------------

  typedef json11::Json::array J11Array;
  typedef json11::Json::object J11Object;

  template<class Collection>
  J11Array toPrimJsonArray(const Collection& col)
  {
    std::vector<json11::Json> js;
    for(auto v : col)
      js.push_back(v);
    return js;
{'fraction_non_alphanumeric': 0.13345323741007195, 'fraction_numerical': 0.023741007194244605, 'mean_word_length': 3.635, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4634422', 'n_tokens_mistral': 945, 'n_tokens_neox': 878, 'n_words': 295}