| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, 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 | #include "gate/utilities.hpp" | ||
| 31 | |||
| 32 | namespace gate | ||
| 33 | { | ||
| 34 | namespace enc | ||
| 35 | { | ||
| 36 | |||
| 37 | 2 | IniFile::IniFile() | |
| 38 | { | ||
| 39 | 2 | result_t result = gate_inifile_store_create(&this->impl); | |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
| 41 | 2 | } | |
| 42 | 1 | IniFile::IniFile(IniFile const& src) | |
| 43 | { | ||
| 44 | 1 | result_t result = gate_inifile_store_copy(&this->impl, &src.impl); | |
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 46 | 1 | } | |
| 47 | 1 | IniFile& IniFile::operator=(IniFile const& src) | |
| 48 | { | ||
| 49 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (this != &src) |
| 50 | { | ||
| 51 | 1 | gate_inifile_store_t store = GATE_INIT_EMPTY; | |
| 52 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_inifile_store_copy(&store, src.c_impl()); |
| 53 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 54 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | gate_inifile_store_destroy(this->c_impl()); |
| 55 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | gate_mem_copy(this->c_impl(), &store, sizeof(store)); |
| 56 | } | ||
| 57 | 1 | return *this; | |
| 58 | } | ||
| 59 | 6 | IniFile::~IniFile() noexcept | |
| 60 | { | ||
| 61 | 3 | gate_inifile_store_destroy(&this->impl); | |
| 62 | 3 | } | |
| 63 | |||
| 64 | 7 | gate_inifile_store_t const* IniFile::c_impl() const | |
| 65 | { | ||
| 66 | 7 | return &this->impl; | |
| 67 | } | ||
| 68 | 16 | gate_inifile_store_t* IniFile::c_impl() | |
| 69 | { | ||
| 70 | 16 | return &this->impl; | |
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | 2 | void IniFile::addSection(String const& section) | |
| 75 | { | ||
| 76 | 2 | result_t result = gate_inifile_store_add_section(this->c_impl(), section.c_impl()); | |
| 77 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
| 78 | 2 | } | |
| 79 | |||
| 80 | 3 | bool IniFile::removeSection(String const& section) | |
| 81 | { | ||
| 82 | 3 | result_t result = gate_inifile_store_remove_section(this->c_impl(), section.c_impl()); | |
| 83 |
2/3✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
3 | switch (result) |
| 84 | { | ||
| 85 | 1 | case GATE_RESULT_OK_UNCHANGED: | |
| 86 | case GATE_RESULT_NOMATCH: | ||
| 87 | 1 | return false; | |
| 88 | 2 | case GATE_RESULT_OK: | |
| 89 | 2 | return true; | |
| 90 | ✗ | default: | |
| 91 | ✗ | GATEXX_RAISE_EXCEPTION(result, NULL, 0); | |
| 92 | ✗ | return false; | |
| 93 | } | ||
| 94 | } | ||
| 95 | 1 | Array<String> IniFile::listSections() const | |
| 96 | { | ||
| 97 | gate_array_t arr; | ||
| 98 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_inifile_store_list_sections(this->c_impl(), &arr); |
| 99 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 100 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | return gate::util::createStringArray(arr).toArray(); |
| 101 | } | ||
| 102 | |||
| 103 | 1 | Array<String> IniFile::listSectionKeys(String const& section) const | |
| 104 | { | ||
| 105 | gate_array_t arr; | ||
| 106 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | result_t result = gate_inifile_store_list_section_keys(this->c_impl(), section.c_impl(), &arr); |
| 107 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 108 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | return gate::util::createStringArray(arr).toArray(); |
| 109 | } | ||
| 110 | |||
| 111 | 4 | void IniFile::set(String const& section, String const& key, String const& value) | |
| 112 | { | ||
| 113 | 4 | result_t result = gate_inifile_store_set(this->c_impl(), section.c_impl(), key.c_impl(), value.c_impl()); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
| 115 | 4 | } | |
| 116 | 4 | String IniFile::get(String const& section, String const& key) const | |
| 117 | { | ||
| 118 | 4 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 119 |
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); |
| 120 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
| 121 | 8 | return String::createFrom(tmp); | |
| 122 | } | ||
| 123 | 5 | bool IniFile::remove(String const& section, String const& key) | |
| 124 | { | ||
| 125 | 5 | result_t result = gate_inifile_store_remove(this->c_impl(), section.c_impl(), key.c_impl()); | |
| 126 |
2/3✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
5 | switch (result) |
| 127 | { | ||
| 128 | 1 | case GATE_RESULT_OK_UNCHANGED: | |
| 129 | case GATE_RESULT_NOMATCH: | ||
| 130 | 1 | return false; | |
| 131 | 4 | case GATE_RESULT_OK: | |
| 132 | 4 | return true; | |
| 133 | ✗ | default: | |
| 134 | ✗ | GATEXX_RAISE_ERROR(result); | |
| 135 | ✗ | return false; | |
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | 1 | void IniFile::load(Stream& inputStream) | |
| 140 | { | ||
| 141 | 1 | result_t result = gate_inifile_store_load(&this->impl, inputStream.c_impl()); | |
| 142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 143 | 1 | } | |
| 144 | 1 | void IniFile::save(Stream& outputStream) | |
| 145 | { | ||
| 146 | 1 | result_t result = gate_inifile_store_save(&this->impl, outputStream.c_impl()); | |
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 148 | 1 | } | |
| 149 | |||
| 150 | ✗ | void IniFile::importEntries(Property const& sourcePropTree) | |
| 151 | { | ||
| 152 | ✗ | result_t result = gate_inifile_store_import(&this->impl, sourcePropTree.c_impl()); | |
| 153 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 154 | ✗ | } | |
| 155 | ✗ | Property IniFile::exportEntries() | |
| 156 | { | ||
| 157 | ✗ | Property prop; | |
| 158 | ✗ | result_t result = gate_inifile_store_export(&this->impl, prop.c_impl()); | |
| 159 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 160 | ✗ | return prop; | |
| 161 | } | ||
| 162 | |||
| 163 | 1 | Property IniFile::parse(String const& sourceText) | |
| 164 | { | ||
| 165 | 1 | Property prop; | |
| 166 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | result_t result = gate_inifile_parse_string(sourceText.c_impl(), prop.c_impl()); |
| 167 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 168 | 1 | return prop; | |
| 169 | } | ||
| 170 | 1 | Property IniFile::parse(Stream& sourceStream) | |
| 171 | { | ||
| 172 | 1 | Property prop; | |
| 173 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | result_t result = gate_inifile_parse(sourceStream.c_impl(), prop.c_impl()); |
| 174 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 175 | 1 | return prop; | |
| 176 | } | ||
| 177 | |||
| 178 | 1 | void IniFile::build(Property const& source, StringBuilder& targetText) | |
| 179 | { | ||
| 180 | 1 | result_t result = gate_inifile_build_string(source.c_impl(), targetText.c_impl()); | |
| 181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 182 | 1 | } | |
| 183 | 1 | void IniFile::build(Property const& source, Stream& targetStream) | |
| 184 | { | ||
| 185 | 1 | result_t result = gate_inifile_build(source.c_impl(), targetStream.c_impl()); | |
| 186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 187 | 1 | } | |
| 188 | |||
| 189 | |||
| 190 | } // end of namespace enc | ||
| 191 | } // end of namesapce gate | ||
| 192 |