Git Product home page Git Product logo

fty's Introduction

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<MyPolicy> Loader{};

Code Example

#include "Fty.hpp"
#include <iostream>
#include <cstdlib>

int 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<fty::AsLowercase> 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

fty's People

Contributors

davschneller avatar sebwolf-de avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.