Choreonoid  1.8
AbstractSeq.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_ABSTRACT_SEQ_H
7 #define CNOID_UTIL_ABSTRACT_SEQ_H
8 
9 #include "NullOut.h"
10 #include <string>
11 #include <vector>
12 #include <memory>
13 #include <functional>
14 #include "exportdecl.h"
15 
16 namespace cnoid {
17 
18 class Mapping;
19 class YAMLWriter;
20 
21 class CNOID_EXPORT AbstractSeq
22 {
23 protected:
24  AbstractSeq(const char* seqType);
25  AbstractSeq(const AbstractSeq& org);
26 
27 public:
28  virtual ~AbstractSeq();
29 
30  virtual AbstractSeq& operator=(const AbstractSeq& rhs);
31 
32  virtual std::shared_ptr<AbstractSeq> cloneSeq() const = 0;
33 
34  void copySeqProperties(const AbstractSeq& source);
35 
36  const std::string& seqType() const {
37  return seqType_;
38  }
39 
40  virtual double getFrameRate() const = 0;
41  virtual void setFrameRate(double frameRate) = 0;
42  static double defaultFrameRate();
43 
44  double getTimeStep() const;
45  void setTimeStep(double timeStep);
46 
47  double getTimeOfFrame(int frame) const;
48  int getFrameOfTime(double time) const;
49 
50  virtual double getOffsetTime() const = 0;
51  virtual void setOffsetTime(double time) = 0;
52  int getOffsetTimeFrame() const;
53 
54  virtual int getNumFrames() const = 0;
55  virtual void setNumFrames(int n, bool clearNewElements = false) = 0;
56 
57  void setTimeLength(double length, bool clearNewElements = false){
58  return setNumFrames(static_cast<int>(length * getFrameRate()), clearNewElements);
59  }
60 
67  double getTimeLength() const;
68 
69  const std::string& seqContentName() {
70  return contentName_;
71  }
72 
73  virtual void setSeqContentName(const std::string& name);
74 
75  bool readSeq(const Mapping* archive, std::ostream& os = nullout());
76  bool writeSeq(YAMLWriter& writer);
77 
79  const std::string& seqMessage() const;
80 
81 protected:
82  void setSeqType(const std::string& type);
83 
84  virtual bool doReadSeq(const Mapping* archive, std::ostream& os);
85  virtual bool doWriteSeq(YAMLWriter& writer, std::function<void()> additionalPartCallback);
86 
88  void clearSeqMessage() { }
89 
91  void addSeqMessage(const std::string& message) { }
92 
93 private:
94  std::string seqType_;
95  std::string contentName_;
96 };
97 
98 
99 class CNOID_EXPORT AbstractMultiSeq : public AbstractSeq
100 {
101 public:
102  AbstractMultiSeq(const char* seqType);
104  virtual ~AbstractMultiSeq();
105 
106  using AbstractSeq::operator=;
107  AbstractMultiSeq& operator=(const AbstractMultiSeq& rhs);
108 
109  virtual std::shared_ptr<AbstractSeq> cloneSeq() const = 0;
110 
111  void copySeqProperties(const AbstractMultiSeq& source);
112 
113  virtual void setDimension(int numFrames, int numParts, bool clearNewElements = false) = 0;
114 
115  virtual void setNumParts(int numParts, bool clearNewElements = false) = 0;
116  virtual int getNumParts() const = 0;
117 
118  virtual int partIndex(const std::string& partLabel) const;
119  virtual const std::string& partLabel(int partIndex) const;
120 
121 protected:
122  virtual bool doWriteSeq(YAMLWriter& writer, std::function<void()> additionalPartCallback);
123  std::vector<std::string> readSeqPartLabels(const Mapping* archive);
124  bool writeSeqPartLabels(YAMLWriter& writer);
125 };
126 
127 #ifdef CNOID_BACKWARD_COMPATIBILITY
128 typedef std::shared_ptr<AbstractSeq> AbstractSeqPtr;
129 typedef std::shared_ptr<AbstractMultiSeq> AbstractMultiSeqPtr;
130 #endif
131 
132 }
133 
134 #endif
cnoid::AbstractSeq::seqContentName
const std::string & seqContentName()
Definition: AbstractSeq.h:69
cnoid::AbstractSeq::seqType
const std::string & seqType() const
Definition: AbstractSeq.h:36
cnoid::Mapping
Definition: ValueTree.h:253
cnoid::YAMLWriter
Definition: YAMLWriter.h:16
cnoid::AbstractSeq::setTimeLength
void setTimeLength(double length, bool clearNewElements=false)
Definition: AbstractSeq.h:57
cnoid::AbstractMultiSeq
Definition: AbstractSeq.h:99
NullOut.h
cnoid::nullout
std::ostream & nullout()
Definition: NullOut.cpp:26
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::AbstractSeq::clearSeqMessage
void clearSeqMessage()
deprecated. Use the os parameter of readSeq to get messages in reading
Definition: AbstractSeq.h:88
cnoid::AbstractSeq
Definition: AbstractSeq.h:21
cnoid::AbstractSeq::addSeqMessage
void addSeqMessage(const std::string &message)
deprecated. Use the os parameter of readSeq to get messages in reading
Definition: AbstractSeq.h:91