Go to the documentation of this file.
6 #include <unordered_map>
7 #include <unordered_set>
11 #include <boost/thread/mutex.hpp>
20 const std::type_info& (*get_type)();
25 static const std::type_info&
id() {
return typeid(T); }
30 template<
typename T>
bool is_type()
const {
44 class String:
public std::vector<char>{
47 String(
const std::string &str) : std::vector<char>(str.begin(), str.end()) {}
48 operator const char * ()
const {
51 operator const std::string ()
const {
52 return std::string(begin(), end());
67 *(T*)&(
buffer.front()) = t;
71 BOOST_THROW_EXCEPTION(std::bad_cast());
81 BOOST_THROW_EXCEPTION(std::length_error(
"buffer empty"));
86 template<
typename T>
const T &
get()
const{
88 BOOST_THROW_EXCEPTION(std::bad_cast());
90 BOOST_THROW_EXCEPTION(std::length_error(
"buffer empty"));
92 return *(T*)&(
buffer.front());
117 #define THROW_WITH_KEY(e,k) BOOST_THROW_EXCEPTION(boost::enable_error_info(e) << ObjectDict::key_info(k))
123 static size_t fromString(
const std::string &str);
126 Key(
const uint16_t i) :
hash((i<<16)| 0xFFFF) {}
127 Key(
const uint16_t i,
const uint8_t s):
hash((i<<16)| s) {}
133 operator std::string()
const;
179 Entry(
const Code c,
const uint16_t i,
const uint16_t t,
const std::string & d,
const bool r =
true,
const bool w =
true,
bool m =
false,
const HoldAny def =
HoldAny(),
const HoldAny init =
HoldAny()):
182 Entry(
const uint16_t i,
const uint8_t s,
const uint16_t t,
const std::string & d,
const bool r =
true,
const bool w =
true,
bool m =
false,
const HoldAny def =
HoldAny(),
const HoldAny init =
HoldAny()):
195 return *
at(
Key(i,s));
200 bool has(uint16_t i, uint8_t s)
const{
203 bool has(uint16_t i)
const{
211 return dict_.insert(std::make_pair(is_sub?
Key(e->index,e->sub_index):
Key(e->index),e)).second;
214 typedef std::unordered_map<Key, EntryConstSharedPtr, KeyHash>
ObjectDictMap;
215 bool iterate(ObjectDictMap::const_iterator &it)
const;
216 typedef std::list<std::pair<std::string, std::string> >
Overlay;
222 typedef boost::error_info<struct tag_objectdict_key, ObjectDict::Key>
key_info;
226 return dict_.at(key);
228 catch(
const std::out_of_range &e){
243 T (*
adder)(
const uint8_t &,
const T &);
245 static T
add(
const uint8_t &u,
const T &t) {
253 if(TypeGuard::create<T>() == val.
type() ){
260 BOOST_THROW_EXCEPTION(std::bad_cast());
270 std::ostream&
operator<<(std::ostream& stream,
const ObjectDict::Key &k);
304 return *(T*)&(
buffer.front());
335 boost::mutex::scoped_lock lock(
mutex);
339 template<
typename T>
const T
get(
bool cached) {
340 boost::mutex::scoped_lock lock(
mutex);
342 if(!
entry->readable){
347 if(
entry->constant) cached =
true;
349 if(!
valid || !cached){
355 template<
typename T>
void set(
const T &val) {
356 boost::mutex::scoped_lock lock(
mutex);
358 if(!
entry->writable){
359 if(access<T>() != val){
368 boost::mutex::scoped_lock lock(
mutex);
369 if(!
valid || val != access<T>() ){
370 if(!
entry->writable){
397 return data->get<T>(
false);
408 if(!
data) BOOST_THROW_EXCEPTION(
PointerInvalid(
"ObjectStorage::Entry::get_cached()") );
410 return data->get<T>(
true);
425 if(!
data)
return false;
427 data->set_cached(val);
452 return *(
data->entry);
459 typedef std::unordered_map<ObjectDict::Key, DataSharedPtr, ObjectDict::KeyHash>
ObjectStorageMap;
470 boost::mutex::scoped_lock lock(
mutex_);
472 ObjectStorageMap::iterator it =
storage_.find(key);
480 if(!e->def_val.is_empty()){
484 if(!e->def_val.type().valid() || e->def_val.type() == type) {
491 std::pair<ObjectStorageMap::iterator, bool> ok =
storage_.insert(std::make_pair(key, data));
495 if(!it->second->type_guard.is_type<T>()){
501 size_t map(uint16_t index, uint8_t sub_index,
const ReadFunc & read_delegate,
const WriteFunc & write_delegate);
513 template<
typename T>
void entry(
Entry<T> &e, uint16_t index, uint8_t sub_index){
560 template<
typename T,
typename R>
static R *
branch_type(
const uint16_t data_type){
581 throw std::bad_cast();
void entry(Entry< T > &e, uint16_t index, uint8_t sub_index)
std::function< void(const std::string &)> WriteStringFuncType
bool simple_boot_up_master
const String & data() const
T(* adder)(const uint8_t &, const T &)
std::function< void(const ObjectDict::Entry &, const String &)> WriteFunc
void entry(Entry< T > &e, uint16_t index)
uint8_t sub_index() const
const ObjectDict::EntryConstSharedPtr entry
ReadStringFuncType getStringReader(const ObjectDict::Key &key, bool cached=false)
boost::error_info< struct tag_objectdict_key, ObjectDict::Key > key_info
bool insert(bool is_sub, EntryConstSharedPtr e)
const EntryConstSharedPtr & get(const Key &k) const
std::shared_ptr< const ObjectDict > ObjectDictConstSharedPtr
static size_t fromString(const std::string &str)
const Entry & operator()(uint16_t i) const
HoldAny(const TypeGuard &t)
Key(const uint16_t i, const uint8_t s)
TypeGuard(const std::type_info &(*ti)(), const size_t s)
static ObjectDictSharedPtr fromFile(const std::string &path, const Overlay &overlay=Overlay())
const Entry & operator()(uint16_t i, uint8_t s) const
bool has(uint16_t i) const
Entry(ObjectStorageSharedPtr storage, uint16_t index)
Entry< T > entry(uint16_t index)
bool has(uint16_t i, uint8_t s) const
String(const std::string &str)
Entry< T > entry(uint16_t index, uint8_t sub_index)
std::size_t operator()(const Key &k) const
bool has(const Key &k) const
const DeviceInfo device_info
Entry(const uint16_t i, const uint8_t s, const uint16_t t, const std::string &d, const bool r=true, const bool w=true, bool m=false, const HoldAny def=HoldAny(), const HoldAny init=HoldAny())
std::shared_ptr< ObjectDict > ObjectDictSharedPtr
std::shared_ptr< ObjectStorage > ObjectStorageSharedPtr
const std::type_info &(* get_type)()
WriteFunc write_delegate_
std::function< void(const ObjectDict::Entry &, String &)> ReadFunc
ObjectStorageMap storage_
Data(const ObjectDict::Key &k, const ObjectDict::EntryConstSharedPtr &e, const TypeGuard &t, const ReadFunc &r, const WriteFunc &w)
std::list< std::pair< std::string, std::string > > Overlay
Data(const ObjectDict::Key &k, const ObjectDict::EntryConstSharedPtr &e, const T &val, const ReadFunc &r, const WriteFunc &w)
static const T apply(const HoldAny &val, const uint8_t &u)
HoldAny(const std::string &t)
bool operator==(const Key &other) const
bool operator==(const TypeGuard &other) const
ObjectDict::ObjectDictSharedPtr ObjectDictSharedPtr
const ObjectDict::Key key
Data(const Data &)=delete
bool entry(Entry< T > &e, const ObjectDict::Key &k)
static R * branch_type(const uint16_t data_type)
WriteStringFuncType getStringWriter(const ObjectDict::Key &key, bool cached=false)
std::function< std::string()> ReadStringFuncType
std::unordered_set< uint32_t > baudrates
std::unordered_map< Key, EntryConstSharedPtr, KeyHash > ObjectDictMap
AccessException(const std::string &w)
const TypeGuard type_guard
static TypeGuard create()
Entry< T > entry(const ObjectDict::Key &key)
#define THROW_WITH_KEY(e, k)
void init(const ObjectDict::Key &key)
static const std::type_info & id()
std::size_t hash_value(ObjectDict::Key const &k)
bool set_cached(const T &val)
static T add(const uint8_t &u, const T &t)
bool dynamic_channels_supported
std::shared_ptr< Data > DataSharedPtr
void set_delegates(const ReadFunc &r, const WriteFunc &w)
const ObjectDictConstSharedPtr dict_
Entry(ObjectStorageSharedPtr storage, uint16_t index, uint8_t sub_index)
std::unordered_map< ObjectDict::Key, DataSharedPtr, ObjectDict::KeyHash > ObjectStorageMap
const ObjectDict::Entry & desc() const
Entry(const Code c, const uint16_t i, const uint16_t t, const std::string &d, const bool r=true, const bool w=true, bool m=false, const HoldAny def=HoldAny(), const HoldAny init=HoldAny())
Data & operator=(const Data &)=delete
Entry(ObjectStorageSharedPtr storage, const ObjectDict::Key &k)
bool simple_boot_up_slave
size_t map(const ObjectDict::EntryConstSharedPtr &e, const ObjectDict::Key &key, const ReadFunc &read_delegate, const WriteFunc &write_delegate)
bool iterate(ObjectDictMap::const_iterator &it) const
const EntryConstSharedPtr & at(const Key &key) const
const TypeGuard & type() const
void set_cached(const T &val)
ObjectDict(const DeviceInfo &info)
std::unordered_set< uint16_t > dummy_usage
const HoldAny & value() const
ObjectStorage(ObjectDictConstSharedPtr dict, uint8_t node_id, ReadFunc read_delegate, WriteFunc write_delegate)
void init_nolock(const ObjectDict::Key &key, const ObjectDict::EntryConstSharedPtr &entry)
std::shared_ptr< const Entry > EntryConstSharedPtr
Key(const std::string &str)
ObjectStorage::ObjectStorageSharedPtr ObjectStorageSharedPtr
std::ostream & operator<<(std::ostream &stream, const NodeIdOffset< T > &n)
canopen_master
Author(s): Mathias Lüdtke
autogenerated on Wed Mar 2 2022 00:52:26