CCA
State.cpp
Go to the documentation of this file.
00001 /* ============================================================
00002  *
00003  * This file is a part of CCA project
00004  *
00005  * Copyright (C) 2011 by Arne Nordmann <anordman at cor-lab dot uni-bielefeld dot de>
00006  *
00007  * This file may be licensed under the terms of the
00008  * GNU Lesser General Public License Version 3 (the ``LGPL''),
00009  * or (at your option) any later version.
00010  *
00011  * Software distributed under the License is distributed
00012  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
00013  * express or implied. See the LGPL for the specific language
00014  * governing rights and limitations.
00015  *
00016  * You should have received a copy of the LGPL along with this
00017  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
00018  * or write to the Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  * The development of this software was supported by:
00022  *   CoR-Lab, Research Institute for Cognition and Robotics
00023  *     Bielefeld University
00024  *
00025  * ============================================================ */
00026 
00027 #include "State.h"
00028 
00029 #include <sstream>
00030 
00031 using namespace std;
00032 
00033 namespace cca {
00034 
00035 ComponentStatePtr ComponentState::PERSISTED() {
00036     return ComponentStatePtr(new ComponentState(ComponentState::STATE_PERSIST));
00037 }
00038 
00039 ComponentStatePtr ComponentState::LOADED() {
00040     return ComponentStatePtr(new ComponentState(ComponentState::STATE_LOAD));
00041 }
00042 
00043 ComponentStatePtr ComponentState::PAUSED() {
00044     return ComponentStatePtr(new ComponentState(ComponentState::STATE_PAUSE));
00045 }
00046 
00047 ComponentStatePtr ComponentState::RESET() {
00048     return ComponentStatePtr(new ComponentState(ComponentState::STATE_RESET));
00049 }
00050 
00051 ComponentStatePtr ComponentState::STOPPED() {
00052     return ComponentStatePtr(new ComponentState(ComponentState::STATE_OFF));
00053 }
00054 
00055 ComponentStatePtr ComponentState::EXECUTION() {
00056     return ComponentStatePtr(new ComponentState(ComponentState::STATE_EXEC));
00057 }
00058 
00059 ComponentStatePtr ComponentState::ONLINELEARNING() {
00060     return ComponentStatePtr(new ComponentState(ComponentState::STATE_ONLLEARN));
00061 }
00062 
00063 ComponentStatePtr ComponentState::OFFLINELEARNING() {
00064     return ComponentStatePtr(
00065             new ComponentState(ComponentState::STATE_OFFLLEARN));
00066 }
00067 
00068 ComponentStatePtr ComponentState::DATAACQUISITION() {
00069     return ComponentStatePtr(
00070             new ComponentState(ComponentState::STATE_ACQUIRE));
00071 }
00072 
00073 ComponentState::State ComponentState::getState() const {
00074     return this->state;
00075 }
00076 
00077 ComponentState::ComponentState(ComponentState::State st) :
00078         DataTransferObject(), state(st) {
00079 }
00080 
00081 ComponentState::~ComponentState() {
00082 }
00083 
00084 std::string ComponentState::print() const {
00085     ostringstream outstream(ostringstream::out);
00086     switch (this->state) {
00087     case STATE_RESET:
00088         outstream << "<Reset>";
00089         break;
00090     case STATE_PAUSE:
00091         outstream << "<Paused>";
00092         break;
00093     case STATE_ACQUIRE:
00094         outstream << "<DataAcquisition>";
00095         break;
00096     case STATE_OFFLLEARN:
00097         outstream << "<OfflineLearning>";
00098         break;
00099     case STATE_ONLLEARN:
00100         outstream << "<OnlineLearning>";
00101         break;
00102     case STATE_EXEC:
00103         outstream << "<Execution>";
00104         break;
00105     case STATE_LOAD:
00106         outstream << "<Loaded>";
00107         break;
00108     case STATE_PERSIST:
00109         outstream << "<Saved>";
00110         break;
00111     case STATE_OFF:
00112         outstream << "<Stopped>";
00113         break;
00114     default:
00115         outstream << "<IllegalState>";
00116         break;
00117     }
00118     return outstream.str();
00119 }
00120 
00121 bool operator==(ComponentStatePtr const a, ComponentStatePtr const b) {
00122     return (a->getState() == b->getState());
00123 }
00124 
00125 bool operator==(ComponentState const a, ComponentState const b) {
00126     return (a.getState() == b.getState());
00127 }
00128 
00129 bool operator!=(ComponentState const a, ComponentState const b) {
00130     return !(a == b);
00131 }
00132 
00133 }