File: parameterName.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (151 lines) | stat: -rw-r--r-- 3,843 bytes parent folder | download | duplicates (2)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/***********************************************/
/**
* @file parameterName.cpp
*
* @brief Parameter name representation.
*
* @author Sebastian Strasser
* @date 2017-05-23
*
*/
/***********************************************/

#include "base/importStd.h"
#include "base/string.h"
#include "base/parameterName.h"

/***********************************************/

ParameterName::ParameterName(const std::string &object, const std::string &type, const std::string &temporal, const Time &timeStart, const Time &timeEnd)
  : object(object), type(type), temporal(temporal)
{
  try
  {
    if(timeStart != Time())
    {
      std::stringstream ss;
      ss<<timeStart.dateTimeStr();
      if(timeEnd != Time())
        ss<<"_"<<timeEnd.dateTimeStr();
      interval = ss.str();
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

ParameterName::ParameterName(const std::string &object, const std::string &type, const std::string &temporal, const std::string &interval)
  : object(object), type(type), temporal(temporal), interval(interval)
{
}

/***********************************************/

ParameterName ParameterName::fromStr(const std::string &str)
{
  try
  {
    std::vector<std::string> parts = String::split(str, sep);

    ParameterName parameterName;
    if(parts.size() > 0) parameterName.object   = parts.at(0);
    if(parts.size() > 1) parameterName.type     = parts.at(1);
    if(parts.size() > 2) parameterName.temporal = parts.at(2);
    if(parts.size() > 3) parameterName.interval = parts.at(3);
    if(parts.size() > 4) throw(Exception("Parameter name contains more than four parts: "+str));

    return parameterName;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

Bool ParameterName::combine(const ParameterName &name)
{
  try
  {
    if(!fuzzyMatch(name))
      return FALSE;

    if(object.empty())   object   = name.object;
    if(type.empty())     type     = name.type;
    if(interval.empty()) interval = name.interval;
    if(temporal.empty()) temporal = name.temporal;

    return TRUE;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

Bool ParameterName::fuzzyMatch(const ParameterName &other) const
{
  try
  {
    return (object   == other.object   || object.empty()   || other.object.empty())   &&
           (type     == other.type     || type.empty()     || other.type.empty())     &&
           (interval == other.interval || interval.empty() || other.interval.empty()) &&
           (temporal == other.temporal || temporal.empty() || other.temporal.empty());
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

Bool ParameterName::operator==(const ParameterName &other) const
{
  try
  {
    return (object == other.object) && (type == other.type ) && (interval == other.interval ) && (temporal == other.temporal);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

Bool ParameterName::operator<(const ParameterName &other) const
{
  try
  {
    Int compareObject = object.compare(other.object);
    if(compareObject < 0) return TRUE;
    if(compareObject > 0) return FALSE;

    Int compareType = type.compare(other.type);
    if(compareType < 0) return TRUE;
    if(compareType > 0) return FALSE;

    Int compareInterval = interval.compare(other.interval);
    if(compareInterval < 0) return TRUE;
    if(compareInterval > 0) return FALSE;

    Int compareTemporal = temporal.compare(other.temporal);
    if(compareTemporal < 0) return TRUE;

    return FALSE;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/