FunctionBehavior.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2016, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_BLOCKS_FUNCTIONBEHAVIOR_H
#define SURGSIM_BLOCKS_FUNCTIONBEHAVIOR_H
#include <functional>
#include <string>
#include "SurgSim/Framework/Behavior.h"
namespace SurgSim
{
namespace Blocks
{
SURGSIM_STATIC_REGISTRATION(FunctionBehavior);
class FunctionBehavior : public SurgSim::Framework::Behavior
{
public:
explicit FunctionBehavior(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Blocks::FunctionBehavior);
void setFunction(std::function<void(double)> function);
void setTargetManagerType(int type);
int getTargetManagerType() const override;
void update(double dt) override;
private:
bool doInitialize() override;
bool doWakeUp() override;
int m_targetManager;
std::function<void(double)> m_function;
};
};
};
#endif // SURGSIM_BLOCKS_FUNCTIONBEHAVIOR_H
SurgSim::Blocks::FunctionBehavior::getTargetManagerType
int getTargetManagerType() const override
Specifies which manger will handle this behavior.
Definition: FunctionBehavior.cpp:47
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Blocks::FunctionBehavior::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Blocks::FunctionBehavior)
SurgSim::Blocks::FunctionBehavior
A Behavior that can run any callable target in its update function.
Definition: FunctionBehavior.h:71
SurgSim::Blocks::FunctionBehavior::FunctionBehavior
FunctionBehavior(const std::string &name)
Constructor.
Definition: FunctionBehavior.cpp:28
SurgSim::Blocks::FunctionBehavior::m_function
std::function< void(double)> m_function
The function to run in update.
Definition: FunctionBehavior.h:101
SurgSim::Blocks::FunctionBehavior::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: FunctionBehavior.cpp:58
SurgSim::Blocks::FunctionBehavior::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: FunctionBehavior.cpp:70
Behavior.h
SurgSim::Blocks::FunctionBehavior::setFunction
void setFunction(std::function< void(double)> function)
Set the function to run in this behavior&#39;s update.
Definition: FunctionBehavior.cpp:52
SurgSim::Blocks::FunctionBehavior::setTargetManagerType
void setTargetManagerType(int type)
Set which manager will handle this behavior.
Definition: FunctionBehavior.cpp:40
SurgSim::Blocks::FunctionBehavior::m_targetManager
int m_targetManager
The manager type that will handle this behavior.
Definition: FunctionBehavior.h:98
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim::Blocks::FunctionBehavior::update
void update(double dt) override
Update the behavior.
Definition: FunctionBehavior.cpp:35