Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/encode/inifiles.hpp" | ||
30 | |||
31 | namespace gate | ||
32 | { | ||
33 | namespace enc | ||
34 | { | ||
35 | |||
36 | 2 | IniFile::IniFile() | |
37 | { | ||
38 | 2 | result_t result = gate_inifile_store_create(&this->impl); | |
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
40 | 2 | } | |
41 | ✗ | IniFile::IniFile(IniFile const& src) | |
42 | { | ||
43 | ✗ | result_t result = gate_inifile_store_copy(&this->impl, &src.impl); | |
44 | ✗ | GATEXX_CHECK_ERROR(result); | |
45 | ✗ | } | |
46 | ✗ | IniFile& IniFile::operator=(IniFile const& src) | |
47 | { | ||
48 | ✗ | if (this != &src) | |
49 | { | ||
50 | ✗ | gate_inifile_store_t store = GATE_INIT_EMPTY; | |
51 | ✗ | result_t result = gate_inifile_store_copy(&store, src.c_impl()); | |
52 | ✗ | GATEXX_CHECK_ERROR(result); | |
53 | ✗ | gate_inifile_store_destroy(this->c_impl()); | |
54 | ✗ | gate_mem_copy(this->c_impl(), &store, sizeof(store)); | |
55 | } | ||
56 | ✗ | return *this; | |
57 | } | ||
58 | 4 | IniFile::~IniFile() noexcept | |
59 | { | ||
60 | 2 | gate_inifile_store_destroy(&this->impl); | |
61 | 2 | } | |
62 | |||
63 | 4 | gate_inifile_store_t const* IniFile::c_impl() const | |
64 | { | ||
65 | 4 | return &this->impl; | |
66 | } | ||
67 | 6 | gate_inifile_store_t* IniFile::c_impl() | |
68 | { | ||
69 | 6 | return &this->impl; | |
70 | } | ||
71 | |||
72 | |||
73 | 2 | void IniFile::addSection(String const& section) | |
74 | { | ||
75 | 2 | result_t result = gate_inifile_store_add_section(this->c_impl(), section.c_impl()); | |
76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
77 | 2 | } | |
78 | |||
79 | ✗ | bool IniFile::removeSection(String const& section) | |
80 | { | ||
81 | ✗ | result_t result = gate_inifile_store_remove_section(this->c_impl(), section.c_impl()); | |
82 | ✗ | switch (result) | |
83 | { | ||
84 | ✗ | case GATE_RESULT_OK_UNCHANGED: | |
85 | case GATE_RESULT_NOMATCH: | ||
86 | ✗ | return false; | |
87 | ✗ | case GATE_RESULT_OK: | |
88 | ✗ | return true; | |
89 | ✗ | default: | |
90 | ✗ | GATEXX_RAISE_EXCEPTION(result, NULL, 0); | |
91 | ✗ | return false; | |
92 | } | ||
93 | } | ||
94 | |||
95 | 4 | void IniFile::set(String const& section, String const& key, String const& value) | |
96 | { | ||
97 | 4 | result_t result = gate_inifile_store_set(this->c_impl(), section.c_impl(), key.c_impl(), value.c_impl()); | |
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
99 | 4 | } | |
100 | 4 | String IniFile::get(String const& section, String const& key) const | |
101 | { | ||
102 | 4 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
103 |
1/2✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | result_t result = gate_inifile_store_get(this->c_impl(), section.c_impl(), key.c_impl(), &tmp); |
104 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
105 | 8 | return String::createFrom(tmp); | |
106 | } | ||
107 | ✗ | bool IniFile::remove(String const& section, String const& key) | |
108 | { | ||
109 | ✗ | result_t result = gate_inifile_store_remove(this->c_impl(), section.c_impl(), key.c_impl()); | |
110 | ✗ | switch (result) | |
111 | { | ||
112 | ✗ | case GATE_RESULT_OK_UNCHANGED: | |
113 | case GATE_RESULT_NOMATCH: | ||
114 | ✗ | return false; | |
115 | ✗ | case GATE_RESULT_OK: | |
116 | ✗ | return true; | |
117 | ✗ | default: | |
118 | ✗ | GATEXX_RAISE_ERROR(result); | |
119 | ✗ | return false; | |
120 | } | ||
121 | } | ||
122 | |||
123 | 1 | void IniFile::load(Stream& inputStream) | |
124 | { | ||
125 | 1 | result_t result = gate_inifile_store_load(&this->impl, inputStream.c_impl()); | |
126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
127 | 1 | } | |
128 | 1 | void IniFile::save(Stream& outputStream) | |
129 | { | ||
130 | 1 | result_t result = gate_inifile_store_save(&this->impl, outputStream.c_impl()); | |
131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
132 | 1 | } | |
133 | |||
134 | ✗ | void IniFile::importEntries(Property const& sourcePropTree) | |
135 | { | ||
136 | ✗ | result_t result = gate_inifile_store_import(&this->impl, sourcePropTree.c_impl()); | |
137 | ✗ | GATEXX_CHECK_ERROR(result); | |
138 | ✗ | } | |
139 | ✗ | Property IniFile::exportEntries() | |
140 | { | ||
141 | ✗ | Property prop; | |
142 | ✗ | result_t result = gate_inifile_store_export(&this->impl, prop.c_impl()); | |
143 | ✗ | GATEXX_CHECK_ERROR(result); | |
144 | ✗ | return prop; | |
145 | } | ||
146 | |||
147 | ✗ | Property IniFile::parse(String const& sourceText) | |
148 | { | ||
149 | ✗ | Property prop; | |
150 | ✗ | result_t result = gate_inifile_parse_string(sourceText.c_impl(), prop.c_impl()); | |
151 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
152 | ✗ | return prop; | |
153 | } | ||
154 | ✗ | Property IniFile::parse(Stream& sourceStream) | |
155 | { | ||
156 | ✗ | Property prop; | |
157 | ✗ | result_t result = gate_inifile_parse(sourceStream.c_impl(), prop.c_impl()); | |
158 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
159 | ✗ | return prop; | |
160 | } | ||
161 | |||
162 | ✗ | void IniFile::build(Property const& source, StringBuilder& targetText) | |
163 | { | ||
164 | ✗ | result_t result = gate_inifile_build_string(source.c_impl(), targetText.c_impl()); | |
165 | ✗ | GATEXX_CHECK_ERROR(result); | |
166 | ✗ | } | |
167 | ✗ | void IniFile::build(Property const& source, Stream& targetStream) | |
168 | { | ||
169 | ✗ | result_t result = gate_inifile_build(source.c_impl(), targetStream.c_impl()); | |
170 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
171 | ✗ | } | |
172 | |||
173 | |||
174 | } // end of namespace enc | ||
175 | } // end of namesapce gate | ||
176 |