Developer documentation
Version 3.0.3-105-gd3941f44
key_value.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __file_key_value_h__
18#define __file_key_value_h__
19
20#include <fstream>
21#include "mrtrix.h"
22#include "types.h"
23
24namespace MR
25{
26 namespace File
27 {
28
29 class OFStream;
30
31 namespace KeyValue
32 {
33
34
35
37 public:
38 Reader () { }
39 Reader (const std::string& file, const char* first_line = nullptr) {
40 open (file, first_line);
41 }
42
43 void open (const std::string& file, const char* first_line = nullptr);
44 bool next ();
45 void close () {
46 in.close();
47 }
48
49 const std::string& key () const throw () {
50 return (K);
51 }
52 const std::string& value () const throw () {
53 return (V);
54 }
55 const std::string& name () const throw () {
56 return (filename);
57 }
58
59 protected:
60 std::string K, V, filename;
61 std::ifstream in;
62 };
63
64
65
66
68 const KeyValues& keyvals,
69 const std::string& prefix,
70 const bool add_to_command_history = true);
71
72
73
74 }
75 }
76}
77
78#endif
79
const std::string & key() const
Definition: key_value.h:49
const std::string & value() const
Definition: key_value.h:52
void open(const std::string &file, const char *first_line=nullptr)
Reader(const std::string &file, const char *first_line=nullptr)
Definition: key_value.h:39
const std::string & name() const
Definition: key_value.h:55
open output files for writing, checking for pre-existing file if necessary
Definition: ofstream.h:39
#define NOMEMALIGN
Definition: memory.h:22
void write(File::OFStream &out, const KeyValues &keyvals, const std::string &prefix, const bool add_to_command_history=true)
Definition: base.h:24
std::map< std::string, std::string > KeyValues
used in various places for storing key-value pairs
Definition: types.h:238