11 #ifndef __PhaseRanges_H
12 #define __PhaseRanges_H
15 #include "TextInterfaceAttribute.h"
20 enum Unit { Bins, Turns, Degrees, Radians,
21 Milliseconds, Seconds, Minutes, Hours };
23 std::ostream& operator << (std::ostream&, Unit);
24 std::istream& operator >> (std::istream&, Unit&);
35 std::ostream& insertion (std::ostream&)
const;
36 std::istream& extraction (std::istream&);
39 HasUnit (Unit u = Turns) { nbin=0; period=0; unit=u; insert_units =
false; }
41 unsigned get_bin (
double value)
const;
42 double get_as (Unit,
double value,
bool round_down=
false)
const;
43 double get_scale (Unit)
const;
45 void set_unit( Unit u ) { unit = u; }
46 Unit get_unit ()
const {
return unit; }
48 void set_nbin(
unsigned N ) { nbin = N; }
51 void set_period(
double P_ms ) { period = P_ms; }
55 class Value :
public HasUnit
62 void set_value(
double v ) { value = v; }
63 double get_value ()
const {
return value; }
65 unsigned get_bin ()
const {
return HasUnit::get_bin(value); }
66 double get_as (Unit u)
const {
return HasUnit::get_as(u, value); }
68 Value as (Unit)
const;
70 friend std::ostream& operator<< (std::ostream&,
const Value&);
71 friend std::istream& operator>> (std::istream&, Value&);
74 std::ostream& operator<< (std::ostream&,
const Value&);
75 std::istream& operator>> (std::istream&, Value&);
78 class Range :
public HasUnit,
public ::Range
80 ::Range& asRange () {
return *
this; }
81 const ::Range& asRange ()
const {
return *
this; }
88 friend std::ostream& operator<< (std::ostream&,
const Range&);
89 friend std::istream& operator>> (std::istream&, Range&);
91 std::pair<unsigned,unsigned> get_bins ()
const;
92 std::pair<double,double> get_as (Unit)
const;
94 Range as (Unit)
const;
98 class Ranges :
public HasUnit,
public ::Ranges
100 ::Ranges& asRanges () {
return *
this; }
101 const ::Ranges& asRanges ()
const {
return *
this; }
104 friend std::ostream& operator<< (std::ostream&,
const Ranges&);
105 friend std::istream& operator>> (std::istream&,
Ranges&);
116 mutable ToString tostr;
117 mutable Phase::Unit unit;
118 mutable bool unit_specified;
124 void set_modifiers (
const std::string& modifiers)
const
127 std::cerr <<
"ToStringPolicy<Phase::HasUnit>::set_modifiers" << std::endl;
130 unit = fromstring<Phase::Unit> (modifiers);
131 unit_specified =
true;
134 void reset_modifiers ()
const
136 unit_specified =
false;
140 std::string operator () (
const Type& t)
const
143 std::cerr <<
"ToStringPolicy<Phase::HasUnit>::operator" << std::endl;
145 if (this->unit_specified)
146 return tostr( t.as(this->unit) );
153 namespace TextInterface
180 class numeric_limits<Phase::Value> {
182 static const int digits10 = numeric_limits<double>::digits10;
186 class numeric_limits<
Phase::Range> {
188 static const int digits10 = numeric_limits<double>::digits10;
192 class numeric_limits<
Phase::Ranges> {
194 static const int digits10 = numeric_limits<double>::digits10;
198 #endif // !__PhaseRanges_H