SPH
SpecialEntries.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "math/Curve.h"
9 #include "run/VirtualSettings.h"
10 
12 
13 enum class IntervalBound {
14  LOWER,
15  UPPER,
16 };
17 
19 template <typename TEnum>
20 class IntervalEntry : public IVirtualEntry {
21 private:
22  Settings<TEnum>& settings;
23  TEnum id;
24  std::string name;
25  IntervalBound bound;
26 
27 public:
29  const TEnum id,
30  const std::string& name,
31  const IntervalBound bound)
32  : settings(settings)
33  , id(id)
34  , name(name)
35  , bound(bound) {}
36 
37  virtual bool enabled() const override {
38  return true;
39  }
40 
41  virtual bool set(const Value& value) override {
42  const Interval i = settings.template get<Interval>(id);
43  Float lower = i.lower();
44  Float upper = i.upper();
45  if (bound == IntervalBound::LOWER) {
46  lower = value.get<Float>();
47  } else {
48  upper = value.get<Float>();
49  }
50  settings.set(id, Interval(lower, upper));
51  return true;
52  }
53 
54  virtual Value get() const override {
55  const Interval i = settings.template get<Interval>(id);
56  if (bound == IntervalBound::LOWER) {
57  return i.lower();
58  } else {
59  return i.upper();
60  }
61  }
62 
63  virtual bool isValid(const Value& UNUSED(value)) const override {
64  return true;
65  }
66 
67  virtual Type getType() const override {
69  }
70 
71  virtual std::string getName() const override {
72  return name;
73  }
74 };
75 
76 template <typename TEnum>
78  const TEnum id,
79  const std::string& name,
80  const IntervalBound bound) {
81  return makeAuto<IntervalEntry<TEnum>>(settings, id, name, bound);
82 }
83 
85 class CurveEntry : public IExtraEntry {
86 private:
87  Curve curve;
88 
89 public:
90  CurveEntry() = default;
91 
92  CurveEntry(const Curve& curve)
93  : curve(curve) {}
94 
95  Curve getCurve() const {
96  return curve;
97  }
98 
99  virtual std::string toString() const override;
100 
101  virtual void fromString(const std::string& s) override;
102 
103  virtual AutoPtr<IExtraEntry> clone() const override;
104 };
105 
106 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
IntervalBound
INLINE AutoPtr< IVirtualEntry > makeEntry(Settings< TEnum > &settings, const TEnum id, const std::string &name, const IntervalBound bound)
Object providing connection between component parameters and values exposed to the user.
Wrapper of pointer that deletes the resource from destructor.
Definition: AutoPtr.h:15
Special entry allowing to access and (de)serialize a curve.
CurveEntry(const Curve &curve)
CurveEntry()=default
Curve getCurve() const
virtual void fromString(const std::string &s) override
virtual AutoPtr< IExtraEntry > clone() const override
virtual std::string toString() const override
Represents a user-defined function, defined by a set of points interpolated by either piecewise linea...
Definition: Curve.h:19
Provides an interface for implementing new types of entries.
Represents a virtual entry in the settings.
Entry connecting to either lower or upper bound of an interval stored in settings.
virtual Value get() const override
Returns the currently stored value.
virtual std::string getName() const override
Returns a descriptive name of the entry.
virtual bool isValid(const Value &UNUSED(value)) const override
virtual bool enabled() const override
Returns if this entry is currently enabled.
virtual Type getType() const override
Returns the type of this entry.
IntervalEntry(Settings< TEnum > &settings, const TEnum id, const std::string &name, const IntervalBound bound)
virtual bool set(const Value &value) override
Modifies the current value of the entry.
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
INLINE Float lower() const
Returns lower bound of the interval.
Definition: Interval.h:74
INLINE Float upper() const
Returns upper bound of the interval.
Definition: Interval.h:79
Generic object containing various settings and parameters of the run.
Definition: Settings.h:108
Settings & set(const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0)
Saves a value into the settings.
Definition: Settings.h:226
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Definition: Variant.h:171
INLINE T & get()
Returns the stored value.
Definition: Variant.h:335