-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from fktn-k/feature/181_support_tag
#181 support tag for scalars
- Loading branch information
Showing
32 changed files
with
3,436 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <fkYAML/node.hpp> | ||
|
||
int main() | ||
{ | ||
// create a YAML node. | ||
fkyaml::node n = 123; | ||
|
||
// set a tag name to the node. | ||
n.add_tag_name("!!int"); | ||
std::cout << n.get_tag_name() << std::endl; | ||
|
||
// overwrite it with a new one. | ||
n.add_tag_name("!!foo"); | ||
std::cout << n.get_tag_name() << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
!!int | ||
!!foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
#include <fkYAML/node.hpp> | ||
|
||
int main() | ||
{ | ||
// create a YAML node. | ||
fkyaml::node n = 123; | ||
|
||
// try to get a tag name before any tag name has been set. | ||
try | ||
{ | ||
std::cout << n.get_tag_name() << std::endl; | ||
} | ||
catch (const fkyaml::exception& e) | ||
{ | ||
std::cout << e.what() << std::endl; | ||
} | ||
|
||
// set a tag name to the node. | ||
n.add_tag_name("!!int"); | ||
std::cout << n.get_tag_name() << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
No tag name has been set. | ||
!!int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
#include <fkYAML/node.hpp> | ||
|
||
int main() | ||
{ | ||
// create a YAML node. | ||
fkyaml::node n = {{"foo", true}}; | ||
|
||
// check if the node has a tag name. | ||
std::cout << std::boolalpha << n.has_tag_name() << std::endl; | ||
|
||
// set a tag name. | ||
n.add_tag_name("!!map"); | ||
|
||
// check if the node has a tag name again. | ||
std::cout << std::boolalpha << n.has_tag_name() << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
false | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<small>Defined in header [`<fkYAML/node.hpp>`](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp)</small> | ||
|
||
# <small>fkyaml::basic_node::</small>add_tag_name | ||
|
||
```cpp | ||
void add_tag_name(const std::string& tag_name); | ||
void add_tag_name(std::string&& tag_name); | ||
``` | ||
Adds a tag name to the YAML node. | ||
If the basic_node has already had any tag name, the new tag name overwrites the old one. | ||
## **Parameters** | ||
***`tag_name`*** [in] | ||
: A tag name. This should not be empty. | ||
???+ Example | ||
```cpp | ||
--8<-- "examples/ex_basic_node_add_tag_name.cpp" | ||
``` | ||
|
||
output: | ||
```bash | ||
--8<-- "examples/ex_basic_node_add_tag_name.output" | ||
``` | ||
|
||
## **See Also** | ||
|
||
* [basic_node](index.md) | ||
* [get_tag_name](get_tag_name.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<small>Defined in header [`<fkYAML/node.hpp>`](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp)</small> | ||
|
||
# <small>fkyaml::basic_node::</small>get_tag_name | ||
|
||
```cpp | ||
const std::string& get_tag_name() const; | ||
``` | ||
|
||
Gets the tag name associated to the YAML node. | ||
Some tag name must be set before calling this API. | ||
Calling [`has_tag_name`](has_tag_name.md) to see if the node has any tag name beforehand. | ||
|
||
## **Return Value** | ||
|
||
The tag name associated to the node. | ||
If no tag name has been set, an [`fkyaml::exception`](../exception/index.md) will be thrown. | ||
|
||
???+ Example | ||
|
||
```cpp | ||
--8<-- "examples/ex_basic_node_get_tag_name.cpp" | ||
``` | ||
|
||
output: | ||
```bash | ||
--8<-- "examples/ex_basic_node_get_tag_name.output" | ||
``` | ||
|
||
## **See Also** | ||
|
||
* [basic_node](index.md) | ||
* [has_tag_name](has_tag_name.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<small>Defined in header [`<fkYAML/node.hpp>`](https://github.com/fktn-k/fkYAML/blob/develop/include/fkYAML/node.hpp)</small> | ||
|
||
# <small>fkyaml::basic_node::</small>has_tag_name | ||
|
||
```cpp | ||
bool has_tag_name() const noexcept; | ||
``` | ||
|
||
Check if the YAML node has a tag name. | ||
|
||
## **Return Value** | ||
|
||
`true` if the YAML node has a tag name, `false` otherwise. | ||
|
||
???+ Example | ||
|
||
```cpp | ||
--8<-- "examples/ex_basic_node_has_tag_name.cpp" | ||
``` | ||
|
||
output: | ||
```bash | ||
--8<-- "examples/ex_basic_node_has_tag_name.output" | ||
``` | ||
|
||
## **See Also** | ||
|
||
* [basic_node](index.md) | ||
* [add_tag_name](add_tag_name.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// _______ __ __ __ _____ __ __ __ | ||
/// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library | ||
/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.3 | ||
/// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML | ||
/// | ||
/// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani <fktn.dev@gmail.com> | ||
/// SPDX-License-Identifier: MIT | ||
/// | ||
/// @file | ||
|
||
#ifndef FK_YAML_DETAIL_DIRECTIVE_SET_HPP_ | ||
#define FK_YAML_DETAIL_DIRECTIVE_SET_HPP_ | ||
|
||
#include <string> | ||
#include <map> | ||
|
||
#include <fkYAML/detail/macros/version_macros.hpp> | ||
#include <fkYAML/detail/types/yaml_version_t.hpp> | ||
|
||
/// @namespace fkyaml | ||
/// @brief namespace for fkYAML library. | ||
FK_YAML_NAMESPACE_BEGIN | ||
|
||
/// @namespace detail | ||
/// @brief namespace for internal implementaions of fkYAML library. | ||
namespace detail | ||
{ | ||
|
||
/// @brief The set of directives for a YAML document. | ||
struct directive_set | ||
{ | ||
/// The YAML version used for the YAML document. | ||
yaml_version_t version {yaml_version_t::VER_1_2}; | ||
/// Whether or not the YAML version has been specified. | ||
bool is_version_specified {false}; | ||
/// The prefix of the primary handle. | ||
std::string primary_handle_prefix {}; | ||
/// The prefix of the secondary handle. | ||
std::string secondary_handle_prefix {}; | ||
/// The map of handle-prefix pairs. | ||
std::map<std::string /*handle*/, std::string /*prefix*/> named_handle_map {}; | ||
}; | ||
|
||
} // namespace detail | ||
|
||
FK_YAML_NAMESPACE_END | ||
|
||
#endif /* FK_YAML_DETAIL_DIRECTIVE_SET_HPP_ */ |
Oops, something went wrong.