SPH
SpecialEntries.cpp
Go to the documentation of this file.
1 #include "run/SpecialEntries.h"
2 
4 
5 std::string CurveEntry::toString() const {
6  std::stringstream ss;
7  for (Size i = 0; i < curve.getPointCnt(); ++i) {
8  const CurvePoint p = curve.getPoint(i);
9  ss << p.x << " " << p.y << " ";
10  if (i < curve.getPointCnt() - 1) {
11  ss << curve.getSegment(i) << " ";
12  }
13  }
14  return ss.str();
15 }
16 
17 void CurveEntry::fromString(const std::string& s) {
18  std::stringstream ss(s);
19  Array<CurvePoint> points;
20  Array<bool> flags;
21  while (ss) {
22  CurvePoint p;
23  ss >> p.x >> p.y;
24  points.push(p);
25 
26  bool f;
27  ss >> f;
28  flags.push(f);
29  }
30  curve = Curve(std::move(points));
31  for (Size i = 0; i < flags.size() - 1; ++i) {
32  curve.setSegment(i, flags[i]);
33  }
34 }
35 
37  return makeAuto<CurveEntry>(curve);
38 }
39 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
Additional bindings to IVirtualSettings.
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
INLINE TCounter size() const noexcept
Definition: Array.h:193
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
const CurvePoint & getPoint(const Size idx) const
Returns the position of idx-th point.
Definition: Curve.cpp:99
Size getPointCnt() const
Returns the number of points defining the curve.
Definition: Curve.cpp:95
void setSegment(const Size idx, const bool cubic)
Modifies the interpolation type of idx-th segment.
Definition: Curve.cpp:130
bool getSegment(const Size idx) const
Returns the interpolation type of idx-th segment.
Definition: Curve.cpp:126
Float x
Definition: Curve.h:9
Float y
Definition: Curve.h:10