diff --git a/include/core/state_block/has_state_blocks.h b/include/core/state_block/has_state_blocks.h index 1e965ce8fa87c785c5a1684fad1cf7522e2abc52..0527407da7354ecc01fda1230a69a93458654fc0 100644 --- a/include/core/state_block/has_state_blocks.h +++ b/include/core/state_block/has_state_blocks.h @@ -18,6 +18,52 @@ namespace wolf typedef std::unordered_map<std::string, StateBlockPtr> StateBlockMap; +class StateBlockComposite +{ + public: + StateBlockComposite() = default; + virtual ~StateBlockComposite() = default; + + const StateBlockMap& getStateBlockMap() const; + + // These act on all state blocks. Per-block action must be done through state_block.fix() or through extended API in derived classes of this. + virtual void fix(); + virtual void unfix(); + virtual bool isFixed() const; + + virtual StateBlockPtr emplace(const std::string& _sb_type, const StateBlockPtr& _sb); + virtual unsigned int erase(const std::string& _sb_type); + virtual unsigned int erase(const char _sb_type); + unsigned int count(const std::string& _sb_type) const { return state_block_map_.count(_sb_type); } + unsigned int count(const StateBlockPtr& _sb) const; + StateBlockPtr at(const std::string& _sb_type) const; + bool set(const std::string _sb_type, const StateBlockPtr& _sb); + bool key(const StateBlockPtr& _sb, std::string& _key) const; + StateBlockMap::const_iterator find(const StateBlockPtr& _sb) const; + + // Emplace derived state blocks (angle, quaternion, etc). + template<typename SB, typename ... Args> + std::shared_ptr<SB> emplace(const std::string& _sb_type, ProblemPtr _problem, Args&&... _args_of_derived_state_block_constructor); + + // Emplace base state blocks. + template<typename ... Args> + inline StateBlockPtr emplace(const std::string& _sb_type, ProblemPtr _problem, Args&&... _args_of_base_state_block_constructor); + + // Perturb state with noise + void perturb(double amplitude = 0.01); + + // Plus operator + void plus(const VectorComposite& _dx); + + // Get composite of state vectors (not blocks) + VectorComposite getStateComposite() const; + bool getStateComposite(VectorComposite& _state) const; + void setStateComposite(const VectorComposite& _state); + + private: + StateBlockMap state_block_map_; +}; + class HasStateBlocks {