Program Listing for File ConfigParser.h

Return to documentation for file (necsim/ConfigParser.h)

// This file is part of necsim project which is released under MIT license.
// See file **LICENSE.txt** or visit for full license details.

#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <stdexcept>
#include <vector>
#include <cstring>


#include <unistd.h>


#include <cmath>
#include <cctype>
#include <algorithm>

using namespace std;
using std::string;
namespace necsim
    void importArgs(const unsigned int &argc, char* argv[], vector<string> &comargs);


    struct SectionOption
        string section;
        vector<string> val;
        vector<string> refs;

        SectionOption() : val(), refs()
            section = "nullSectionOption";

        string getOption(string refval);

        friend ostream &operator<<(ostream &os, const SectionOption &k);

        friend istream &operator>>(istream &is, SectionOption &k);

    class ConfigParser
        string config_file;
        bool configSet;
        bool isMain;  // is true if this is the main command line import (and therefore we want to delete the first few
        // command line options)
        bool isFullParser;  // if this is true, each KeyOption structure will be returned after each read.
        vector<SectionOption> configs;  // all config data if full parse is true.
        ConfigParser() : configs()
            config_file = "none";
            configSet = false;
            isMain = false;
            isFullParser = false;

        void setConfig(const string &file, bool main, bool full_parse = false);

        void parseConfig();

        void parseConfig(istream &istream1);

        vector<SectionOption> getSectionOptions();

        void setSectionOption(string section, string reference, string value);

        SectionOption operator[](unsigned long index);

        unsigned long getSectionOptionsSize();

        vector<string> getSections();

        bool hasSection(const string &sec);

        vector<string> getSectionValues(string sec);

        string getSectionOptions(string section, string ref);

        string getSectionOptions(string section, string ref, string def);

        int importConfig(vector<string> &comargs);

        friend ostream &operator<<(ostream &os, const ConfigParser &c);

        friend istream &operator>>(istream &is, ConfigParser &c);