-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.h
85 lines (67 loc) · 2.05 KB
/
Util.h
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
#ifndef _MobiView2_Util_h_
#define _MobiView2_Util_h_
inline Upp::Time
convert_time(const Date_Time &dt) {
s32 year, month, day, hour, minute, second;
dt.year_month_day(&year, &month, &day);
dt.hour_minute_second(&hour, &minute, &second);
return Upp::Time(year, month, day, hour, minute, second);
}
inline Date_Time
convert_time(const Upp::Time &tm) {
Date_Time result(tm.year, tm.month, tm.day);
result.add_timestamp(tm.hour, tm.minute, tm.second);
return result;
}
inline bool
parse_percent_list(String &list_str, std::vector<double> &result) {
bool success = true;
Vector<String> split = Split(list_str, ',');
for(String &str : split) {
double val = StrDbl(str);
if(!IsNull(val) && val >= 0.0 && val <= 100.0)
result.push_back(val);
else
success = false;
}
return success;
}
template<typename Handle_T>
inline Upp::String
make_index_string(Storage_Structure<Handle_T> *structure, Indexes &indexes, Handle_T handle) {
const std::vector<Entity_Id> &index_sets = structure->get_index_sets(handle);
if(index_sets.empty()) return "";
std::vector<std::string> names;
structure->parent->index_data.get_index_names(indexes, names, true);
Upp::String result = "[";
int idx = 0;
bool once = false;
for(const Entity_Id &index_set : index_sets) {
if(idx != 0) result << " ";
result << names[index_set.id];
++idx;
}
result << "]";
return result;
}
inline Upp::String
make_parameter_index_string(Storage_Structure<Entity_Id> *structure, Indexed_Parameter *par) {
const std::vector<Entity_Id> &index_sets = structure->get_index_sets(par->id);
if(index_sets.empty()) return "";
std::vector<std::string> names;
structure->parent->index_data.get_index_names(par->indexes, names, true);
Upp::String result = "[";
int idx = 0;
bool once = false;
for(const Entity_Id &index_set : index_sets) {
if(idx != 0) result << " ";
if(par->locks[index_set.id])
result << "locked(\"" << structure->parent->model->index_sets[index_set]->name << "\")";
else
result << names[index_set.id];
++idx;
}
result << "]";
return result;
}
#endif