/home/jpf/code/cc/project/cmil/src/InputEv.cpp

Go to the documentation of this file.
00001 // =====================================================================================
00002 //       Filename:  InputEv.cpp 
00003 //    Description:  
00004 //        Created:  02/15/2007 08:47:46 PM EST
00005 //       Revision:  none
00006 //       Compiler:  gcc 3.4.6
00007 // 
00008 //         Author:  John P. Feltz 
00009 //          Email:  jfeltz@gmail.com
00010 //        License:  Copyright (c) 2006-2007, John P. Feltz 
00011 //                  This program is free software; you can redistribute it and/or
00012 //                  modify it under the terms of the GNU General Public License as
00013 //                  published by the Free Software Foundation, version 2 of the
00014 //                  License.
00015 //                  This program is distributed in the hope that it will be
00016 //                  useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //                  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018 //                  PURPOSE.
00019 //                  See the GNU General Public License version 2 for more details.
00020 // 
00021 // =====================================================================================
00022 
00023 
00024 #include <iostream>
00025 #include <vector>
00026 
00027 #include <util/Singleton.h>
00028 #include <util/Logger.h>
00029 
00030 #include "InputAction.h"
00031 #include "InputEv.h"
00032 
00033 namespace cmil {
00035   std::string Ev::sdev = std::string(""); 
00036   
00038   unsigned long Ev::smargin = 500;  
00039 
00041   InputAction* const Ev::getAction() const { 
00042     return m_action;
00043   }
00044   
00047   InputAction* const Ev::seqAction() const { 
00048     if(m_sequence) {
00049 //        log_debug("seqAction() returning action from last event in sequence");
00050         return m_sequence->back().getAction();
00051     }
00052 
00053 //    log_debug("seqAction() return the action of this instance instead of the sequence.");
00054     return getAction();
00055   }
00056 
00057   Ev::Sequence* const Ev::getSequence() const { 
00058      return m_sequence;
00059   }
00060 
00064 
00065   Ev& Ev::operator<<(const Ev& event) { 
00067     
00068     if( !seqAction() ) {
00070        if(!m_sequence) {
00071          //log_debug( "(Ev) operator<< initializing new sequence");
00072          m_sequence = new Sequence(1, *this);
00073        }
00074 
00076        m_sequence->push_back(event);
00077 
00078        return *this;  
00079     }
00080     else 
00081       log_error(std::string("(Ev) operator<< addition not possible due to action already applied in sequence. (").append( 
00082       getName()).append(")"));
00083 
00084     return *this;  
00085   }                                           
00086 
00088   Ev& Ev::operator<<(InputAction* action) { 
00089     log_debug("(Ev) operator<<(InputAction* action)" );
00090     
00092     if(!m_sequence) {
00093       m_sequence = new Ev::Sequence(1, *this);
00094       
00095       log_debug("(Ev) operator<< InputAction* : creating sequence "); 
00096     }
00097 
00098     log_debug(std::string("(Ev) operator<< InputAction*  assigning action to: ").append(m_sequence->back().getName()));
00099     
00101     (m_sequence->back()).m_action = action;
00102 
00103     return *this;  
00104   }
00105 
00107   Ev::Ev(const Ev& rhs) {
00108     m_time_margin = rhs.m_time_margin; 
00109     m_ndev        = rhs.m_ndev; 
00110     m_input       = rhs.m_input;
00111     m_dev         = rhs.m_dev;
00112 
00113     m_action = rhs.m_action;
00114 
00116     m_sequence = NULL;
00117   }
00118 
00120   Ev& Ev::operator=(const Ev& rhs) { 
00121     //log_debug("calling Ev& operator=(const Ev& rhs)"); 
00122     m_time_margin = rhs.m_time_margin; 
00123     m_ndev        = rhs.m_ndev; 
00124     m_input       = rhs.m_input;
00125     m_dev         = rhs.m_dev;
00126 
00127     m_action = rhs.m_action;
00128     
00130     m_sequence = NULL;
00131 
00132     return *this;
00133   }
00134 
00135   bool Ev::operator==(const Ev& event) const { 
00136     if( (m_ndev  == event.m_ndev) && (m_dev  == event.m_dev) && (m_input == event.m_input) ) 
00137       return true;
00138 
00139     return false;
00140   }
00141 
00142   bool Ev::operator<(const Ev& event) const { 
00144     if(m_dev < event.m_dev) 
00145       return true;
00146     else if (m_ndev < event.m_ndev)
00147       return true;
00148     else if(m_ndev < event.m_ndev) 
00149       return true;
00150     else if(m_input < event.m_input) 
00151       return true;
00152 
00153     return false;
00154   }
00155 
00156   bool Ev::operator>(const Ev& event) const { 
00158     if(m_dev > event.m_dev) 
00159       return true;
00160     else if (m_ndev > event.m_ndev)
00161       return true;
00162     else if(m_ndev > event.m_ndev) 
00163       return true;
00164     else if(m_input > event.m_input) 
00165       return true;
00166 
00167     return false;
00168   }
00169 }

(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:02 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo