Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seissol/fty
https://github.com/seissol/fty
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/seissol/fty
- Owner: SeisSol
- License: mit
- Created: 2020-08-16T17:46:03.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T10:59:55.000Z (4 months ago)
- Last Synced: 2024-11-05T20:13:38.612Z (3 months ago)
- Language: C++
- Size: 110 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Authors: AUTHORS.txt
Awesome Lists containing this project
README
# fty - Fortran To Yaml
It is a small header-only C++ library which is supposed to help people to start converting their legacy Fortran code to C++. The library reads a text file or lists of strings formatted according to Fortran *NAMELIST I/O* style, and generates a YAML::Node (a hash table) containing retrieved information.
## Requirements
Make sure that you have **yaml-cpp** installed## Exceptions
The library throws the following exceptions in case of a failure during a convertion:
```
fty::exception::FileException
fty::exception::CriticalTextBlockException
fty::exception::CriticalKeyValueError
```
## Policies
The library offers several base policies for storing keys in a generated hash table due to issues related to the case sensitivity.| Name | Description |
|-------------- |-------------------------------------------------- |
| AsOriginal | stores keys as it is given in an input file/list |
| AsUppercase | converts all keys to upper-case |
| AsLowercase | converts all keys to lower-case |If none of the policies fit to your particular problem you can provide yours by defining and providing a class to either *fty::Loader* or *fty::Converter*
#### Policy Example
```
struct MyPolicy {
std::string apply(const std::string& String) {
std::string ConvertedString(String.size(), '\0');
// your code is here
return ConvertedString;
}
};fty::Loader Loader{};
```## Code Example
```
#include "Fty.hpp"
#include
#includeint main(int Argc, char *Argv[]) {
if (Argc != 2) {
std::cerr << "Error: Please, provide an input file\n";
std::cerr << "Example: fty-converter [input file path]\n";
exit(EXIT_FAILURE);
}std::string FileName = Argv[1];
fty::Loader Loader{};
try {
YAML::Node Params = Loader.load(FileName);
std::cout << Params;
}
catch (const fty::exception::FileException& Error) {
std::cerr << Error.what() << std::endl;
}
catch (const std::exception& Error) {
std::cerr << Error.what() << std::endl;
throw Error;
}
return 0;
}
```
See **CMakeLists.txt** as an example of compiling