flippy
a c++20 package for dynamically triangulated membrane simulations.
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#ifndef FLIPPY_UTILS_H
2#define FLIPPY_UTILS_H
7#include <iostream>
8#include <fstream>
9#include <utility>
10#include <filesystem>
11#include <type_traits>
12
13namespace fp {
19using Json = nlohmann::json;
20
26static inline void json_dump(std::string const& file_name, const Json& data)
27{
28 std::ofstream o(file_name + ".json");
29 o << data.dump();
30 o.close();
31}
32
43static Json inline json_read(std::string file_name)
44{
45 auto pos_json = file_name.find_last_of(".json");
46 auto not_json = (file_name.size() - 1!=pos_json);
47 if (not_json) { file_name = file_name + ".json"; }
48 std::ifstream o(file_name);
49 Json data;
50 o >> data;
51 o.close();
52 return data;
53}
54
63template<typename T>
64[[maybe_unused]] static bool is_member(std::vector<T> const& v, T const& el){
65 return (std::find(v.begin(),v.end(), el) != v.end());
66}
68}
69#endif
static void json_dump(std::string const &file_name, const Json &data)
Simple wrapper function around Json objects built in dump() method.
Definition utils.hpp:26
static bool is_member(std::vector< T > const &v, T const &el)
Convenient wrapper around std::find, which only works for std::vectors.
Definition utils.hpp:64
nlohmann::json Json
shortening of the nlohmann::json namespace, which is an external open source library bundled by flipp...
Definition Nodes.hpp:17
static Json json_read(std::string file_name)
Simple wrapper function that reads the content of a text file into a json object.
Definition utils.hpp:43
Definition custom_concepts.hpp:8