w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclSet.ipp
Go to the documentation of this file.
1// $Id: RtclSet.ipp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-22 1091 1.1.4 <float> add float cast (-Wdouble-promotion fix)
8// 2018-12-18 1089 1.1.3 use c++ style casts
9// 2018-12-15 1083 1.1.2 ctor: use rval ref and move semantics
10// 2018-12-14 1081 1.1.1 use std::function instead of boost
11// 2017-02-20 854 1.1 add Rtime
12// 2013-02-12 487 1.0 Initial version
13// ---------------------------------------------------------------------------
14
24#include <climits>
25#include <cfloat>
26
27#include "librtools/Rtime.hpp"
28
29// all method definitions in namespace Retro
30namespace Retro {
31
32//------------------------------------------+-----------------------------------
34
35template <class TP>
36inline RtclSet<TP>::RtclSet(std::function<void(TP)>&& set)
37 : fSet(move(set))
38{}
39
40//------------------------------------------+-----------------------------------
42
43template <class TP>
45{}
46
47//------------------------------------------+-----------------------------------
49
50template <>
51inline void RtclSet<bool>::operator()(RtclArgs& args) const
52{
53 int val;
54 if(Tcl_GetBooleanFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
55 throw Rexception("RtclSet<>::oper()", "conversion error");
56
57 fSet(bool(val));
58 return;
59}
60
61//------------------------------------------+-----------------------------------
63
64template <>
65inline void RtclSet<char>::operator()(RtclArgs& args) const
66{
67 int val;
68 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
69 throw Rexception("RtclSet<>::oper()", "conversion error");
70 if (val < CHAR_MIN || val > CHAR_MAX)
71 throw Rexception("RtclSet<>::oper()",
72 "out of range for type 'char'");
73
74 fSet(char(val));
75 return;
76}
77
78//------------------------------------------+-----------------------------------
80
81template <>
83{
84 int val;
85 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
86 throw Rexception("RtclSet<>::oper()", "conversion error");
87 if (val < SCHAR_MIN || val > SCHAR_MAX)
88 throw Rexception("RtclSet<>::oper()",
89 "out of range for type 'signed char'");
90
91 fSet(static_cast<signed char>(val));
92 return;
93}
94
95//------------------------------------------+-----------------------------------
97
98template <>
100{
101 int val;
102 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
103 throw Rexception("RtclSet<>::oper()", "conversion error");
104 if (static_cast<unsigned int>(val) > UCHAR_MAX)
105 throw Rexception("RtclSet<>::oper()",
106 "out of range for type 'unsigned char'");
107
108 fSet(static_cast<unsigned char>(val));
109 return;
110}
111
112//------------------------------------------+-----------------------------------
114
115template <>
116inline void RtclSet<short>::operator()(RtclArgs& args) const
117{
118 int val;
119 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
120 throw Rexception("RtclSet<>::oper()", "conversion error");
121 if (val < SHRT_MIN || val > SHRT_MAX)
122 throw Rexception("RtclSet<>::oper()",
123 "out of range for type 'short'");
124
125 fSet(short(val));
126 return;
127}
128
129//------------------------------------------+-----------------------------------
131
132template <>
134{
135 int val;
136 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
137 throw Rexception("RtclSet<>::oper()", "conversion error");
138 if (static_cast<unsigned int>(val) > USHRT_MAX)
139 throw Rexception("RtclSet<>::oper()",
140 "out of range for type 'unsigned short'");
141
142 fSet(static_cast<unsigned short>(val));
143 return;
144}
145
146//------------------------------------------+-----------------------------------
148
149template <>
150inline void RtclSet<int>::operator()(RtclArgs& args) const
151{
152 int val;
153 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
154 throw Rexception("RtclSet<>::oper()", "conversion error");
155
156 fSet(val);
157 return;
158}
159
160//------------------------------------------+-----------------------------------
162
163template <>
165{
166 int val;
167 if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
168 throw Rexception("RtclSet<>::oper()", "conversion error");
169
170 fSet(static_cast<unsigned int>(val));
171 return;
172}
173
174//------------------------------------------+-----------------------------------
176
177template <>
178inline void RtclSet<long>::operator()(RtclArgs& args) const
179{
180 long val;
181 if(Tcl_GetLongFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
182 throw Rexception("RtclSet<>::oper()", "conversion error");
183
184 fSet(val);
185 return;
186}
187
188//------------------------------------------+-----------------------------------
190
191template <>
193{
194 long val;
195 if(Tcl_GetLongFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
196 throw Rexception("RtclSet<>::oper()", "conversion error");
197
198 fSet(static_cast<unsigned long>(val));
199 return;
200}
201
202//------------------------------------------+-----------------------------------
204
205template <>
206inline void RtclSet<float>::operator()(RtclArgs& args) const
207{
208 double val;
209 if(Tcl_GetDoubleFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
210 throw Rexception("RtclSet<>::oper()", "conversion error");
211 if (val < -double(FLT_MAX) || val > double(FLT_MAX))
212 throw Rexception("RtclSet<>::oper()",
213 "out of range for type 'float'");
214
215 fSet(float(val));
216 return;
217}
218
219//------------------------------------------+-----------------------------------
221
222template <>
223inline void RtclSet<double>::operator()(RtclArgs& args) const
224{
225 double val;
226 if(Tcl_GetDoubleFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
227 throw Rexception("RtclSet<>::oper()", "conversion error");
228
229 fSet(val);
230 return;
231}
232
233//------------------------------------------+-----------------------------------
235
236template <>
238{
239 char* val = Tcl_GetString(args.CurrentArg());
240 fSet(std::string(val));
241 return;
242}
243
244//------------------------------------------+-----------------------------------
246
247template <>
249{
250 double val;
251 if(Tcl_GetDoubleFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK)
252 throw Rexception("RtclSet<>::oper()", "conversion error");
253
254 fSet(Rtime(val));
255 return;
256}
257
258
259} // end namespace Retro
260
FIXME_docs.
Definition: Rexception.hpp:29
FIXME_docs.
Definition: RtclArgs.hpp:41
Tcl_Obj * CurrentArg() const
FIXME_docs.
Definition: RtclArgs.cpp:435
Tcl_Interp * Interp() const
FIXME_docs.
Definition: RtclArgs.ipp:28
~RtclSet()
FIXME_docs.
Definition: RtclSet.ipp:44
RtclSet(std::function< void(TP)> &&set)
FIXME_docs.
Definition: RtclSet.ipp:36
virtual void operator()(RtclArgs &args) const
FIXME_docs.
Definition: Rtime.hpp:25
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47