claraty::Device_Group Class Reference
#include <device_group.h>
Inheritance diagram for claraty::Device_Group:


Public Member Functions | |
| template<class Sub, class Arg> | |
| int | for_each (bool Sub::*memb_func(const Arg &), const Arg &value) |
| template<class Sub, class Arg1, class Arg2> | |
| int | for_each (bool Sub::*memb_func(const Arg1 &, const Arg2 &), const Arg1 &val1, const Arg2 &val2) |
| unsigned int | get_size () const |
| |
| std::string | get_name () const |
| |
| void | get_devices (std::vector< Device * > &ptr_vec) const |
| Device & | get_device (unsigned int device_index) const throw (std::out_of_range) |
| int | lookup_index (const Device &device) const |
| int | lookup_index (const std::string &name) const |
| void | append (Device &device) throw (std::invalid_argument, std::bad_cast) |
| void | remove (Device &device) throw (std::invalid_argument) |
| Device & | remove (unsigned int device_index) throw (std::out_of_range) |
| template<class Sub, class Arg> | |
| int | for_each (bool Sub::*memb_func(const Arg &), const Arg &value) |
| template<class Sub, class Arg1, class Arg2> | |
| int | for_each (bool Sub::*memb_func(const Arg1 &, const Arg2 &), const Arg1 &val1, const Arg2 &val2) |
| virtual bool | io (FDM_Map map) |
| std::ostream & | display_xml (const char *p=NULL, std::ostream &os=std::cout) const |
Protected Member Functions | |
| virtual bool | _device_type_is_ok (const Device &device) const |
Protected Attributes | |
| std::string | _group_name |
| std::vector< Device * > | _device_vec |
Detailed Description
Definition at line 42 of file device_group.h.
Constructor & Destructor Documentation
| claraty::Device_Group::Device_Group | ( | int | expected_size, | |
| const std::string & | group_name = "" | |||
| ) |
Constructs a group of devices based on the expected size of the group
- Parameters:
-
[in] expected_size The expected size of the group [in] group_name A unique group name which unless specified will be autogenerated
Definition at line 46 of file device_group.cc.
References _device_vec.
00048 : _group_name((group_name.size() == 0) ? 00049 "def_device_group" : group_name) 00050 { 00051 // Allocates sufficient memory to hold the entire group of elements. 00052 _device_vec.reserve ( expected_size ); 00053 }
| virtual claraty::Device_Group::~Device_Group | ( | ) | [inline, virtual] |
| claraty::Device_Group::Device_Group | ( | int | expected_size, | |
| const std::string & | group_name = "" | |||
| ) |
Constructs a group of devices based on the expected size of the group
- Parameters:
-
[in] expected_size The expected size of the group [in] group_name A unique group name which unless specified will be autogenerated
Definition at line 46 of file device_group.cc.
References _device_vec.
00048 : _group_name((group_name.size() == 0) ? 00049 "def_device_group" : group_name) 00050 { 00051 // Allocates sufficient memory to hold the entire group of elements. 00052 _device_vec.reserve ( expected_size ); 00053 }
| virtual claraty::Device_Group::~Device_Group | ( | ) | [inline, virtual] |
Member Function Documentation
| unsigned int claraty::Device_Group::get_size | ( | ) | const [inline] |
- Returns:
- the number of devices currently in this group.
Definition at line 57 of file device_group.h.
References _device_vec.
Referenced by claraty::Camera_Group::_verify_pixel_format(), claraty::Camera_Group::_verify_resize_images(), claraty::Camera_Group::acquire(), for_each(), io(), and lookup_index().
00057 { return _device_vec.size(); }
| std::string claraty::Device_Group::get_name | ( | ) | const [inline] |
- Returns:
- a string containing name of this device group.
Definition at line 60 of file device_group.h.
References _group_name.
Referenced by display_xml(), and lookup_index().
00060 { return _group_name; }
| void claraty::Device_Group::get_devices | ( | std::vector< Device * > & | ptr_vec | ) | const |
- Returns:
- a vector of pointers to all devices in the device list. Devices in the returned vector are in the same order as the device indices. I.e. For all i in 0..A.size()-1: A.lookup_index(ptr_vec[i]) == i
Definition at line 62 of file device_group.cc.
References _device_vec.
00063 { 00064 // This is a copy, so _device_vec is not exposed. 00065 ptr_vec = _device_vec; 00066 }
| Device & claraty::Device_Group::get_device | ( | unsigned int | device_index | ) | const throw (std::out_of_range) |
- Returns:
- a reference to the device_indexTH element of the device list. Throw an exception if device_index is not in the range 0..size()-1.
Definition at line 74 of file device_group.cc.
References AT_FUNCTION.
Referenced by claraty::Camera_Group::get_camera().
00075 { 00076 if (device_index < 0 || device_index >= get_size()) { 00077 std::ostringstream os; 00078 os << AT_FUNCTION << "-- index (" << device_index << ")" 00079 << " out of range of " << (*this) << ", size()=" << get_size() 00080 << endl; 00081 throw std::out_of_range(os.str()); 00082 } 00083 // Note that it is impossible to add a NULL _device_vec entry, so this 00084 // dereference is safe. 00085 return *_device_vec[device_index]; 00086 }
| int claraty::Device_Group::lookup_index | ( | const Device & | device | ) | const |
- Returns:
- the index of the device with the given address, if it is on the device list, or -1 if it is not.
Definition at line 94 of file device_group.cc.
References _device_vec, ERROR, and get_size().
00095 { 00096 for (unsigned int i = 0; i < get_size(); ++i) { 00097 if (&device == _device_vec[i]) return (int)i; 00098 } 00099 return ERROR; 00100 }
Here is the call graph for this function:

| int claraty::Device_Group::lookup_index | ( | const std::string & | name | ) | const |
- Returns:
- the index of the first device in the device list with the given name, or -1 if no device on the list has that name.
Definition at line 108 of file device_group.cc.
References _device_vec, ERROR, get_name(), and get_size().
00109 { 00110 for (unsigned int i = 0; i < get_size(); ++i) { 00111 if (name == _device_vec[i]->get_name()) return (int)i; 00112 } 00113 return ERROR; 00114 }
Here is the call graph for this function:

| void claraty::Device_Group::append | ( | Device & | device | ) | throw (std::invalid_argument, std::bad_cast) |
Add a new device to the end of the device list. Failure occurs if the device is already included in the list, or if the type of the device does not match the type expected by the derived class. An exception is thrown upon failure.
- Parameters:
-
[in] device a constant reference to the device to be added
Definition at line 125 of file device_group.cc.
References AT_FUNCTION.
Referenced by claraty::Camera_Group::Camera_Group().
00126 { 00127 if (lookup_index(device) >= 0) { 00128 std::ostringstream os; 00129 os << AT_FUNCTION << " device " << device << " already in list for " 00130 << endl << "device group=" << (*this); 00131 throw std::invalid_argument(os.str()); 00132 } 00133 if (!_device_type_is_ok(device)) throw std::bad_cast(); 00134 00135 _device_vec.push_back(&device); 00136 }
| void claraty::Device_Group::remove | ( | Device & | device | ) | throw (std::invalid_argument) |
Remove the given device from the device list. An exception is thrown if the device is not in the list.
Definition at line 170 of file device_group.cc.
References AT_FUNCTION.
00171 { 00172 int index = lookup_index(device); 00173 if (index < 0) { 00174 std::ostringstream os; 00175 os << AT_FUNCTION << "--" << device << "is not in list for " << endl 00176 << "device group=" << (*this); 00177 throw std::invalid_argument(os.str()); 00178 } 00179 (void)remove(index); 00180 }
| Device & claraty::Device_Group::remove | ( | unsigned int | device_index | ) | throw (std::out_of_range) |
Remove the device_indexTH device from the device list. The return value is a reference to the removed device. An exception is thrown if device_index is out of range.
Definition at line 145 of file device_group.cc.
References AT_FUNCTION.
00146 { 00147 unsigned int old_size = get_size(); 00148 if (device_index < 0 || device_index >= old_size) { 00149 std::ostringstream os; 00150 os << AT_FUNCTION << "-- index (" << device_index << ")" 00151 << " out of range of " << (*this) << ", size()=" << get_size() 00152 << std::endl; 00153 throw std::out_of_range(os.str()); 00154 } 00155 00156 Device* return_ptr = _device_vec[device_index]; 00157 for (unsigned int i = device_index + 1; i < old_size; ++i) { 00158 _device_vec[i-1] = _device_vec[i]; 00159 } 00160 _device_vec.resize(old_size - 1); 00161 return *return_ptr; 00162 }
| int claraty::Device_Group::for_each | ( | bool Sub::* | memb_func(const Arg &), | |
| const Arg & | value | |||
| ) |
Here's a way to make the group execute function such as set_contrast etc. generic such that we do no not need to define these in the Camera_Group.
This template version should work for members of derived classes which are not members of the base Device class. It assumes a single parameter (of generic type) to the set_X function. A similar template function is supplied for 2 generic params.
Note that this template function is so generic that very little type checking is done.
From a user standpoint the call will look like this:
XYZ_Camera_Group cg(...); cg.for_each(&XYZ_Camera::set_feature, 0.13);
Definition at line 148 of file device_group.h.
| int claraty::Device_Group::for_each | ( | bool Sub::* | memb_func(const Arg1 &, const Arg2 &), | |
| const Arg1 & | val1, | |||
| const Arg2 & | val2 | |||
| ) |
Definition at line 162 of file device_group.h.
| bool claraty::Device_Group::io | ( | FDM_Map | map | ) | [virtual] |
Maps the data members of the device object for sending over a serial medium
- Parameters:
-
[out] map A serial object that contains the device data members
- Returns:
- true if serialization succeeds, false otherwise.
Reimplemented in claraty::Camera_Group.
Definition at line 191 of file device_group.cc.
References _device_vec, _group_name, claraty::FDM_Map::field(), and get_size().
Referenced by claraty::Camera_Group::io().
00192 { 00193 bool ok = true; 00194 int size=get_size(); 00195 ok &= map.field("size", size); 00196 ok &= map.field("name", _group_name); 00197 00198 for (int i=0; i < size; ++i) { 00199 ostringstream dev; 00200 dev << "\n\tdevice" << i; 00201 ok &= map.field(dev.str().c_str(), *_device_vec[i]); 00202 } 00203 return ok; 00204 }
Here is the call graph for this function:

| std::ostream & claraty::Device_Group::display_xml | ( | const char * | pmsg = NULL, |
|
| std::ostream & | os = std::cout | |||
| ) | const |
Output the contents of device in an XML format (not fully implemented)
- Parameters:
-
[in] pmsg a text message to display before the output [in] os output stream with cout as a default
- Returns:
- the formatted output stream
Definition at line 213 of file device_group.cc.
References claraty::XML_Out::get_indentation_space(), and get_name().
Referenced by claraty::operator<<().
00214 { 00215 // Set up the spacing for the indentation of the fields in the file 00216 std::string spacing = ""; 00217 spacing.append(XML_Out::get_indentation_space(), ' '); 00218 os << spacing << "<Device_Group "; 00219 os << "size = \"" << get_name() << "\" "; 00220 os << "name = \"" << get_name() << "\" "; 00221 os << " >"; 00222 return os; 00223 }
Here is the call graph for this function:

| bool claraty::Device_Group::_device_type_is_ok | ( | const Device & | device | ) | const [protected, virtual] |
This function is called from member function append to insure that the derived type of the given device is compatible with the derived type of this Device_Group. Return true if they are compatible, else false.
Definition at line 264 of file device_group.cc.
| int claraty::Device_Group::for_each | ( | bool Sub::* | memb_func(const Arg &), | |
| const Arg & | value | |||
| ) |
Here's a way to make the group execute function such as set_contrast etc. generic such that we do no not need to define these in the Camera_Group.
This template version should work for members of derived classes which are not members of the base Device class. It assumes a single parameter (of generic type) to the set_X function. A similar template function is supplied for 2 generic params.
Note that this template function is so generic that very little type checking is done.
From a user standpoint the call will look like this:
XYZ_Camera_Group cg(...); cg.for_each(&XYZ_Camera::set_feature, 0.13);
Definition at line 45 of file device_group.ipp.
References _device_vec, and get_size().
00047 { 00048 int ok_count = 0; 00049 for (unsigned int i = 0; i < get_size(); i++) { 00050 ok_count += (static_cast<Sub*>(_device_vec[i])->*memb_func)(value); 00051 } 00052 return ok_count; 00053 };
Here is the call graph for this function:

| int claraty::Device_Group::for_each | ( | bool Sub::* | memb_func(const Arg1 &, const Arg2 &), | |
| const Arg1 & | val1, | |||
| const Arg2 & | val2 | |||
| ) |
Definition at line 59 of file device_group.ipp.
References _device_vec, and get_size().
00062 { 00063 int ok_count = 0; 00064 for (unsigned int i = 0; i < get_size(); i++) { 00065 ok_count += (static_cast<Sub*>(_device_vec[i])->*memb_func)(val1, val2); 00066 } 00067 return ok_count; 00068 };
Here is the call graph for this function:

Member Data Documentation
std::string claraty::Device_Group::_group_name [protected] |
std::vector<Device *> claraty::Device_Group::_device_vec [protected] |
Definition at line 96 of file device_group.h.
Referenced by Device_Group(), for_each(), get_devices(), get_size(), io(), and lookup_index().
The documentation for this class was generated from the following files: