-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblitz.cpp
125 lines (104 loc) · 4.1 KB
/
blitz.cpp
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
/*
* Copyright (C) 2014 University of Dundee & Open Microscopy Environment
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <omero/model/${name}I.h>
#include <omero/ClientErrors.h>
::Ice::Object* IceInternal::upCast(::omero::model::${name}I* t) { return t; }
using namespace omero::conversions;
typedef omero::model::enums::Units${name} Units${name};
namespace omero {
namespace model {
{% for cfrom in sorted(equations) %}\
static std::map<Units${name}, ConversionPtr> createMap${cfrom}() {
std::map<Units${name}, ConversionPtr> c;
{% for cto, equation in sorted(equations.get(cfrom, {}).items()) %}\
{% if cfrom != cto %}\
c[enums::${cto}] = ${equation};
{% end %}\
{% end %}\
return c;
}
{% end %}\
static std::map<Units${name},
std::map<Units${name}, ConversionPtr> > makeConversions() {
std::map<Units${name}, std::map<Units${name}, ConversionPtr> > c;
{% for cfrom in sorted(equations) %}\
c[enums::${cfrom}] = createMap${cfrom}();
{% end %}\
return c;
}
static std::map<Units${name}, std::string> makeSymbols(){
std::map<Units${name}, std::string> s;
{% for x in sorted(items) %}\
s[enums::${x.CODE}] = "${x.SYMBOL}";
{% end %}\
return s;
}
std::map<Units${name},
std::map<Units${name}, ConversionPtr> > ${name}I::CONVERSIONS = makeConversions();
std::map<Units${name}, std::string> ${name}I::SYMBOLS = makeSymbols();
${name}I::~${name}I() {}
${name}I::${name}I() : ${name}() {
}
${name}I::${name}I(const double& value, const Units${name}& unit) : ${name}() {
setValue(value);
setUnit(unit);
}
${name}I::${name}I(const ${name}Ptr& value, const Units${name}& target) : ${name}() {
double orig = value->getValue();
Units${name} source = value->getUnit();
if (target == source) {
// No conversion needed
setValue(orig);
setUnit(target);
} else {
ConversionPtr conversion = CONVERSIONS[source][target];
if (!conversion) {
std::stringstream ss;
ss << orig << " " << source;
ss << "cannot be converted to " << target;
throw omero::ClientError(__FILE__, __LINE__, ss.str().c_str());
}
double converted = conversion->convert(orig);
setValue(converted);
setUnit(target);
}
}
Ice::Double ${name}I::getValue(const Ice::Current& /* current */) {
return value;
}
void ${name}I::setValue(Ice::Double _value, const Ice::Current& /* current */) {
value = _value;
}
Units${name} ${name}I::getUnit(const Ice::Current& /* current */) {
return unit;
}
void ${name}I::setUnit(Units${name} _unit, const Ice::Current& /* current */) {
unit = _unit;
}
std::string ${name}I::getSymbol(const Ice::Current& /* current */) {
return SYMBOLS[unit];
}
${name}Ptr ${name}I::copy(const Ice::Current& /* current */) {
${name}Ptr copy = new ${name}I();
copy->setValue(getValue());
copy->setUnit(getUnit());
return copy;
}
}
}