File: ParameterInfo.h

package info (click to toggle)
rna-star 2.7.8a%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,076 kB
  • sloc: cpp: 20,429; awk: 483; ansic: 470; makefile: 181; sh: 31
file content (112 lines) | stat: -rw-r--r-- 3,239 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef PARAMETERSINFO_DEF
#define PARAMETERSINFO_DEF

class ParameterInfoBase {
public:
    string nameString; //string that identifies parameter
    int inputLevel; //where the parameter was defined
    int inputLevelAllowed; //at which input level parameter definition is allowed
    virtual void inputValues(istringstream &streamIn) =0;
    friend std::ostream& operator<< (std::ostream& o, ParameterInfoBase const& b);
    virtual ~ParameterInfoBase() {};
protected:
    virtual void printValues(std::ostream& o) const = 0;
};



inline std::ostream& operator<< (std::ostream& o, ParameterInfoBase const& b) {
    b.printValues(o);
    return o;
};


template <class parameterType>
inline parameterType inputOneValue (istringstream &streamIn) {
    parameterType oneV;
    streamIn >> oneV;
    return oneV;
};
template <>
inline string inputOneValue <string> (istringstream &streamIn) {
    string oneV="";
    streamIn >> ws;//skip whitespace
    if (streamIn.peek()!='"') {//simple parameter with no spaces or "
        streamIn >> oneV;
    } else {
        streamIn.get();//skip "
        getline(streamIn,oneV,'"');
    };
    return oneV;
};


template <class parameterType>
inline void printOneValue (parameterType *value, std::ostream& outStr) {
    outStr << *value;
};
template <>
inline void printOneValue <string> (string *value, std::ostream& outStr) {
    if ((*value).find_first_of(" \t")!=std::string::npos) {//there is white space in the argument, put "" around
        outStr << '\"' << *value <<'\"';
    } else {
        outStr << *value;
    };
};

template <class parameterType>
class ParameterInfoScalar : public ParameterInfoBase {
public:
    parameterType *value;
    vector <parameterType> allowedValues;

    ParameterInfoScalar(int inputLevelIn, int inputLevelAllowedIn, string nameStringIn, parameterType* valueIn) {
        nameString=nameStringIn;
        inputLevel=inputLevelIn;
        inputLevelAllowed=inputLevelAllowedIn;
        value=valueIn;
    };

    void inputValues(istringstream &streamIn) {
        *value=inputOneValue <parameterType> (streamIn);
    };

    ~ParameterInfoScalar() {};
protected:
   virtual void printValues(std::ostream& outStr) const {
       printOneValue(value, outStr);
   };

};

template <class parameterType>
class ParameterInfoVector : public ParameterInfoBase {
public:
    vector <parameterType> *value;
    vector <parameterType> allowedValues;

    ParameterInfoVector(int inputLevelIn, int inputLevelAllowedIn, string nameStringIn, vector <parameterType> *valueIn) {
        nameString=nameStringIn;
        inputLevel=inputLevelIn;
        inputLevelAllowed=inputLevelAllowedIn;
        value=valueIn;
    };

    void inputValues(istringstream &streamIn) {
        (*value).clear();
        while (streamIn.good()) {
            (*value).push_back(inputOneValue <parameterType> (streamIn));
            streamIn >> ws; //remove white space, may arrive at the end of line
        };
    };

    ~ParameterInfoVector() {};
protected:
   virtual void printValues(std::ostream& outStr) const {
       for (int ii=0; ii < (int) (*value).size(); ii++) {
           printOneValue(&(*value).at(ii),outStr);
           outStr<<"   ";
       };
   };
};
#endif