NamedData.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2012-2013, 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_DATASTRUCTURES_NAMEDDATA_H
#define SURGSIM_DATASTRUCTURES_NAMEDDATA_H
#include <memory>
#include <string>
#include <vector>
#include "SurgSim/Framework/Assert.h"
#include "SurgSim/DataStructures/IndexDirectory.h"
namespace SurgSim
{
namespace DataStructures
{
typedef std::unordered_map<int, int> NamedDataCopyMap;
namespace Names
{
static const char* const BUTTON_0 = "button0";
static const char* const BUTTON_1 = "button1";
static const char* const BUTTON_2 = "button2";
static const char* const BUTTON_3 = "button3";
static const char* const BUTTON_4 = "button4";
static const char* const TOOLDOF = "toolDof";
static const char* const POSE = "pose";
static const char* const INPUT_POSE = "inputPose";
static const char* const ANGULAR_VELOCITY = "angularVelocity";
static const char* const LINEAR_VELOCITY = "linearVelocity";
static const char* const INPUT_ANGULAR_VELOCITY = "inputAngularVelocity";
static const char* const INPUT_LINEAR_VELOCITY = "inputLinearVelocity";
static const char* const FORCE = "force";
static const char* const TORQUE = "torque";
static const char* const DAMPER_JACOBIAN = "damperJacobian";
static const char* const SPRING_JACOBIAN = "springJacobian";
static const char* const IS_HOMED = "isHomed";
static const char* const IS_ORIENTATION_HOMED = "isOrientationHomed";
static const char* const IS_POSITION_HOMED = "isPositionHomed";
static const char* const DIGITAL_INPUT_PREFIX = "digitalInput";
static const char* const DIGITAL_OUTPUT_PREFIX = "digitalOutput";
static const char* const TIMER_INPUT_PREFIX = "timerInput";
static const char* const TIMER_OUTPUT_PREFIX = "timerOutput";
static const char* const ANALOG_INPUT_PREFIX = "analogInput";
static const char* const ANALOG_OUTPUT_PREFIX = "analogOutput";
static const char* const PROJECTION_MATRIX = "projectionMatix";
static const char* const LEFT_PROJECTION_MATRIX = "leftProjectionMatix";
static const char* const RIGHT_PROJECTION_MATRIX = "rightProjectionMatix";
static const char* const KEY = "key";
};
template <typename T>
class NamedData
{
public:
inline NamedData();
inline explicit NamedData(std::shared_ptr<const IndexDirectory> directory);
inline explicit NamedData(const std::vector<std::string>& names);
inline NamedData(const NamedData& namedData);
inline NamedData& operator=(const NamedData& namedData);
inline NamedData(NamedData&& namedData);
inline NamedData& operator=(NamedData&& namedData);
inline bool isValid() const;
inline std::shared_ptr<const IndexDirectory> getDirectory() const;
inline int getIndex(const std::string& name) const;
inline std::string getName(int index) const;
inline bool hasEntry(int index) const;
inline bool hasEntry(const std::string& name) const;
inline bool hasData(int index) const;
inline bool hasData(const std::string& name) const;
inline bool get(int index, T* value) const;
inline bool get(const std::string& name, T* value) const;
inline bool set(int index, const T& value);
inline bool set(int index, T&& value);
inline bool set(const std::string& name, const T& value);
inline bool set(const std::string& name, T&& value);
inline bool reset(int index);
inline bool reset(const std::string& name);
inline void resetAll();
inline size_t size() const;
inline int getNumEntries() const;
template <typename N>
void copy(const NamedData<N>& source, const NamedDataCopyMap& map);
void cacheIndex(const std::string& name, int* index) const;
private:
std::shared_ptr<const IndexDirectory> m_directory;
std::vector<T> m_data;
std::vector<bool> m_isDataValid;
};
}; // namespace DataStructures
}; // namespace SurgSim
#include "SurgSim/DataStructures/NamedData-inl.h"
#endif // SURGSIM_DATASTRUCTURES_NAMEDDATA_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::NamedData
A templated dictionary in which data can be accessed by name or index, with immutable names & indices...
Definition: NamedData.h:102
SurgSim::DataStructures::NamedData::m_data
std::vector< T > m_data
The array of values.
Definition: NamedData.h:317
SurgSim::DataStructures::NamedDataCopyMap
std::unordered_map< int, int > NamedDataCopyMap
The type used for copying values between two NamedData objects that cannot assign to each other...
Definition: NamedData.h:32
NamedData-inl.h
IndexDirectory.h
SurgSim::DataStructures::NamedData::m_isDataValid
std::vector< bool > m_isDataValid
The array storing whether the data is currently valid.
Definition: NamedData.h:320
SurgSim::Math::isValid
bool isValid(float value)
Check if a float value is valid.
Definition: Valid-inl.h:98
Assert.h
The header that provides the assertion API.
SurgSim::DataStructures::NamedData::m_directory
std::shared_ptr< const IndexDirectory > m_directory
The mapping between names and indices.
Definition: NamedData.h:314