GenericContainer
GenericContainer a tool for C++ programming
Loading...
Searching...
No Matches
GenericContainerInterface_json.hh
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2013 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Università degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
20#pragma once
21
22#ifndef GENERIC_CONTAINER_INTERFACE_JSON_HH
23#define GENERIC_CONTAINER_INTERFACE_JSON_HH
24
25#include "GenericContainer.hh"
26
27#include <fstream>
28
29namespace GC_namespace {
30
31 using std::ifstream;
32
37
48 inline
49 bool
51 string const & file_name,
53 ) {
54 ifstream stream(file_name.data());
55 gc.clear();
56 return gc.from_json( stream );
57 }
58
69 inline
70 bool
72 istream_type & stream,
74 ) {
75 gc.clear();
76 return gc.from_json( stream );
77 }
78
89 inline
90 bool
92 string const & DATA,
94 ) {
95 istringstream stream(DATA);
96 gc.clear();
97 return gc.from_json(stream);
98 }
99
109 inline
110 void
111 GC_to_JSON( GenericContainer const & gc, std::string & res ) {
112 ostringstream stream;
113 gc.to_json( stream );
114 res = stream.str();
115 }
116
126 inline
127 void
129 GenericContainer const & gc,
130 ostream_type & stream
131 ) {
132 gc.to_json( stream );
133 }
134
138
139}
140
141#endif
142
The GenericContainer class provides a flexible container for storing heterogeneous data types.
Definition GenericContainer.hh:614
bool from_json(istream_type &stream)
void to_json(ostream_type &stream, string_view prefix="") const
void clear()
Clears the content of the GenericContainer, resetting it to an empty state.
Definition GenericContainer.cc:592
void GC_to_JSON(GenericContainer const &gc, std::string &res)
Definition GenericContainerInterface_json.hh:111
bool JSON_to_GC(istream_type &stream, GenericContainer &gc)
Definition GenericContainerInterface_json.hh:71
bool file_JSON_to_GC(string const &file_name, GenericContainer &gc)
Definition GenericContainerInterface_json.hh:50
Definition GenericContainer.cc:68
std::basic_ostream< char > ostream_type
Alias for a character-based output stream.
Definition GenericContainer.hh:109
std::basic_istream< char > istream_type
Alias for a character-based input stream.
Definition GenericContainer.hh:118