Libbarrett  1.2.4
include/barrett/systems/detail/array_editor-inl.h
00001 /*
00002         Copyright 2009, 2010 Barrett Technology <support@barrett.com>
00003 
00004         This file is part of libbarrett.
00005 
00006         This version of libbarrett is free software: you can redistribute it
00007         and/or modify it under the terms of the GNU General Public License as
00008         published by the Free Software Foundation, either version 3 of the
00009         License, or (at your option) any later version.
00010 
00011         This version of libbarrett is distributed in the hope that it will be
00012         useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License along
00017         with this version of libbarrett.  If not, see
00018         <http://www.gnu.org/licenses/>.
00019 
00020         Further, non-binding information about licensing is available at:
00021         <http://wiki.barrett.com/libbarrett/wiki/LicenseNotes>
00022 */
00023 
00024 /*
00025  * array_editor-inl.h
00026  *
00027  *  Created on: Nov 12, 2009
00028  *      Author: dc
00029  */
00030 
00031 
00032 #include <barrett/detail/stl_utils.h>
00033 #include <barrett/systems/abstract/system.h>
00034 
00035 
00036 namespace barrett {
00037 namespace systems {
00038 
00039 
00040 template <typename T>
00041 ArrayEditor<T>::ArrayEditor(const std::string& sysName) :
00042         SingleIO<T, T>(sysName), data()
00043 {
00044         for (size_t i = 0; i < T::SIZE; ++i) {
00045                 elementInputs[i] = new System::Input<double>(this);
00046         }
00047 }
00048 
00049 template <typename T>
00050 ArrayEditor<T>::~ArrayEditor()
00051 {
00052         this->mandatoryCleanUp();
00053         barrett::detail::purge(elementInputs);
00054 }
00055 
00056 
00057 template <typename T>
00058 inline System::Input<double>& ArrayEditor<T>::getElementInput(const size_t i)
00059 {
00060         return *( elementInputs.at(i) );
00061 }
00062 
00063 template <typename T>
00064 void ArrayEditor<T>::operate()
00065 {
00066         data = this->input.getValue();
00067         for (size_t i = 0; i < T::SIZE; ++i) {
00068                 if (elementInputs[i]->valueDefined()) {
00069                         data[i] = elementInputs[i]->getValue();
00070                 }
00071         }
00072 
00073         this->outputValue->setData(&data);
00074 }
00075 
00076 template <typename T>
00077 bool ArrayEditor<T>::inputsValid()
00078 {
00079         return this->input.valueDefined();
00080 }
00081 
00082 
00083 
00084 }
00085 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines