cmil::DeviceInputs Class Reference

#include <InputDevice.h>

Inheritance diagram for cmil::DeviceInputs:

Inheritance graph
[legend]
Collaboration diagram for cmil::DeviceInputs:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::map< const std::string,
InputData *const > 
Inputs

Public Member Functions

 DeviceInputs ()
void cleanup ()
 Cleanup the IputData memory.
void add (const std::string &set_device_name, InputData *input)
DeviceInputsclone () const
void dumpInputs () const
const InputsgetInputs () const
const InputsgetCustomInputs () const
InputData *const getData (bool which, const std::string &name) const
std::string getName () const
bool isEqual (bool match_custom, const DeviceInputs &inputs) const
bool operator== (const DeviceInputs &inputs) const
void removeInput (const std::string &name)
unsigned long int resetIDs (unsigned long int count)
void resetWhichDevice (unsigned long int which_device)
bool setInput (const std::string &old_name, const std::string &new_name)
bool setInputs (const DeviceInputs &dev_inputs)

Static Public Attributes

static const bool use_base = true
 These are here to reduce confusion.
static const bool use_custom = false

Private Member Functions

 DeviceInputs (const Inputs &cloned_base, const Inputs &cloned_custom)
InputData *const getData (const Inputs &inputs, const std::string &name) const
bool match_inputs (const Inputs &first, const Inputs &second) const
 This is a utility function which matches on name existance and data type.
bool erase (const std::string &name, Inputs &inputs)
 This both unallocates the inputdata and removes it from the list, use with care.
bool remove (const std::string &name, Inputs &inputs)
bool renameData (Inputs &inputs, const std::string &old_name, const std::string &new_name)

Private Attributes

Inputs m_base
 Inputs are only added to this container.
Inputs m_custom
 Inputs are customized via this container.

Detailed Description

Definition at line 24 of file InputDevice.h.


Member Typedef Documentation

typedef std::map<const std::string, InputData* const> cmil::DeviceInputs::Inputs

Definition at line 26 of file InputDevice.h.


Constructor & Destructor Documentation

cmil::DeviceInputs::DeviceInputs (  )  [inline]

Definition at line 27 of file InputDevice.h.

Referenced by clone().

00027 {};

Here is the caller graph for this function:

cmil::DeviceInputs::DeviceInputs ( const Inputs cloned_base,
const Inputs cloned_custom 
) [private]

Definition at line 40 of file InputDevice.cpp.

References cmil::InputData::clone(), Logger::log_error(), m_base, and m_custom.

00040                                                                                    {
00041     InputData* input_data = NULL;
00042 
00043     Inputs::const_iterator i, i_custom;
00044     std::string custom_name;
00045 
00046     for(i = cloned_base.begin(); i != cloned_base.end(); ++i) {
00048       input_data = (*i).second->clone();
00049 
00050       std::pair<std::string, InputData* const> input_pair ( (*i).first, input_data ); 
00051       m_base.insert(input_pair); 
00052     }
00053 
00054     if(cloned_custom.size()) {
00055       if(cloned_custom.size() != cloned_base.size()) 
00056         log_error("DevceInputs(cloned_base, cloned_custom) : parameter indexes are not equal in size."); 
00057       else {
00058         i_custom = cloned_custom.begin();
00059 
00060         for(i = m_base.begin(); i != m_base.end(); ++i) {
00061           input_data = i->second;
00062 
00063           std::pair<std::string, InputData* const> input_pair ((*i_custom).first, input_data); 
00064           m_custom.insert(input_pair);  
00065           ++i_custom;
00066         }
00067       }
00068     } 
00069   }

Here is the call graph for this function:


Member Function Documentation

void cmil::DeviceInputs::add ( const std::string &  set_device_name,
InputData input 
)

Definition at line 103 of file InputDevice.cpp.

References cmil::InputData::getName(), Logger::log_error(), m_base, and cmil::InputData::setDevice().

Referenced by cmil::InputDevice::add(), and cmil::tInputIndex< T >::fill_indexes().

00103                                                                        {
00104     if(!input)
00105       log_error("add() passed null input");
00106     else {
00107       if( m_base.find(input->getName()) != m_base.end() )
00108         log_error(std::string("DeviceInputs::add() insertion of ").append(input->getName()).append( 
00109             "failed due to pre-existing input of the same name"));
00110       else {
00111         input->setDevice(device_name);
00112         std::pair<std::string, InputData* const> input_pair (input->getName(), input); 
00113 //        log_debug(std::string("adding: ").append(input->getName()));
00114         m_base.insert(input_pair);  
00115       }
00116     }
00117   }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceInputs::cleanup (  ) 

Cleanup the IputData memory.

Definition at line 72 of file InputDevice.cpp.

References Logger::log_debug(), and m_base.

Referenced by cmil::InputDevice::cleanup().

00072                              {
00073     Inputs::iterator i;
00074     int dcount = 0;
00075 
00076     for(i = m_base.begin() ; i != m_base.end() ; ++i) {
00077       if(i->second) {
00078         delete (i->second);
00079         dcount++;
00080       }
00081     }
00082 
00083     std::ostringstream debug_ss;
00084     debug_ss << "cleanup() deleted memory consisting of : " << dcount  << " addresses.";
00085     log_debug( debug_ss.str() );
00086   }

Here is the call graph for this function:

Here is the caller graph for this function:

DeviceInputs * cmil::DeviceInputs::clone (  )  const

Definition at line 97 of file InputDevice.cpp.

References DeviceInputs(), Logger::log_debug(), m_base, and m_custom.

00097                                           {
00098     log_debug("clone()");
00100     return new DeviceInputs(m_base, m_custom);
00101   }

Here is the call graph for this function:

void cmil::DeviceInputs::dumpInputs (  )  const

Definition at line 88 of file InputDevice.cpp.

References Logger::log_debug(), and m_custom.

Referenced by cmil::InputDevice::dumpInputs().

00088                                       {
00089     for( Inputs::const_iterator i = m_custom.begin(); i != m_custom.end(); ++i) 
00090       log_debug( std::string("Dumping custom, input name: ").append( i->first ) ); 
00091   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::DeviceInputs::erase ( const std::string &  name,
Inputs inputs 
) [private]

This both unallocates the inputdata and removes it from the list, use with care.

Definition at line 120 of file InputDevice.cpp.

References Logger::log_error().

Referenced by removeInput().

00120                                                                 { 
00121     if(inputs.find(name) == inputs.end()) {
00122       log_error("remove() tried to remove non-existant input");
00123       return false;
00124     }
00125     else {
00126       delete inputs[name];
00127       inputs.erase(name);
00128     }
00129 
00130     return true;
00131   } 

Here is the call graph for this function:

Here is the caller graph for this function:

const DeviceInputs::Inputs & cmil::DeviceInputs::getCustomInputs (  )  const

Definition at line 137 of file InputDevice.cpp.

References m_custom.

Referenced by cmil::DeviceRegistry::copyDevice(), isEqual(), and setInputs().

00137                                                                 {
00138     return m_custom;
00139   }

Here is the caller graph for this function:

InputData *const cmil::DeviceInputs::getData ( const Inputs inputs,
const std::string &  name 
) const [private]

Definition at line 154 of file InputDevice.cpp.

References Logger::log_error().

00154                                                                                           {
00155     Inputs::const_iterator i = inputs.find(name);
00156 
00157     if (i != inputs.end() ) { 
00158        //log_debug(std::string("getData() returning data for string: ").append(name)); 
00159        return i->second;
00160     }
00161 
00162     log_error(std::string("getData() returning NULL for string: ").append(name)); 
00163 
00164 //    std::ostringstream num_ss; 
00165 //    for(i = inputs.begin() ; i != inputs.end() ; i++)
00166 //      log_error(std::string("getData() scanned : ").append(i->first)); 
00167 
00168     return NULL;
00169   }

Here is the call graph for this function:

InputData *const cmil::DeviceInputs::getData ( bool  which,
const std::string &  name 
) const

Definition at line 171 of file InputDevice.cpp.

References m_base, and m_custom.

Referenced by cmil::InputDevice::getData().

00171                                                                                     {
00172     if(base_data || (m_custom.size() == 0)) {
00173       //log_debug("getData(bool, name) : calling on base");
00174       return getData(m_base, name);
00175     }
00176 
00177     //log_debug("getData(bool, name) : calling on custom");
00178     return getData(m_custom, name);
00179   }

Here is the caller graph for this function:

const DeviceInputs::Inputs & cmil::DeviceInputs::getInputs (  )  const

Definition at line 133 of file InputDevice.cpp.

References m_base.

Referenced by isEqual(), cmil::Mouse::operator==(), and setInputs().

00133                                                           {
00134     return m_base;
00135   }

Here is the caller graph for this function:

std::string cmil::DeviceInputs::getName (  )  const [virtual]

Implements Logger.

Definition at line 93 of file InputDevice.cpp.

00093                                         {
00094     return "DeviceInputs";
00095   }

bool cmil::DeviceInputs::isEqual ( bool  match_custom,
const DeviceInputs inputs 
) const

Definition at line 193 of file InputDevice.cpp.

References getCustomInputs(), getInputs(), Logger::log_debug(), m_base, m_custom, and match_inputs().

Referenced by cmil::SDL::DefaultMouse::operator==(), operator==(), and setInputs().

00193                                                                                    {
00194     log_debug("isEqual()");
00195     bool is_equal = false;
00196     if(match_custom) 
00197       is_equal = match_inputs(m_custom, devinputs.getCustomInputs());
00198     
00199     is_equal = match_inputs(m_base, devinputs.getInputs());
00200     return is_equal;
00201   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::DeviceInputs::match_inputs ( const Inputs first,
const Inputs second 
) const [private]

This is a utility function which matches on name existance and data type.

Definition at line 204 of file InputDevice.cpp.

References Logger::log_error().

Referenced by isEqual().

00204                                                                                  {
00205     Inputs::const_iterator a, b;
00206 
00207     if(first.size() != second.size()) 
00208       return false;
00209 
00210     for(a = first.begin() ; a != first.end(); ++a) {
00211       b = second.find(a->first);
00212 
00213       if(b == second.end()) {
00214         log_error( "match_inputs() returning false due to input name mismatch");
00215         return false;
00216       }
00217       else if ( typeid(*(a->second)) != typeid(*(b->second)) ) {
00218         log_error( "match_inputs() returning false due to type mismatch");
00219         return false;
00220       }
00221     }
00222       
00223     return true;
00224   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::DeviceInputs::operator== ( const DeviceInputs inputs  )  const

Definition at line 181 of file InputDevice.cpp.

References isEqual(), Logger::log_debug(), and Logger::log_error().

00181                                                                    {
00182     const bool match_custom = true;
00183 
00184     if(isEqual(match_custom, devinputs)) {
00185       log_debug("operator== match_inputs returning true");
00186       return true;
00187     }
00188 
00189     log_error("operator== match_inputs returning false");
00190     return false;
00191   }

Here is the call graph for this function:

bool cmil::DeviceInputs::remove ( const std::string &  name,
Inputs inputs 
) [private]

Definition at line 142 of file InputDevice.cpp.

References Logger::log_debug().

Referenced by removeInput().

00142                                                                  {
00143     if(inputs.find(name) == inputs.end()) {
00144       log_debug("remove() Tried to remove non-existant input.");
00145       return false;
00146     }
00147     else {
00148       inputs.erase(name);
00149     }
00150 
00151     return true;
00152   }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceInputs::removeInput ( const std::string &  name  ) 

Definition at line 226 of file InputDevice.cpp.

References erase(), m_base, m_custom, and remove().

Referenced by cmil::InputDevice::removeInput().

00226                                                       {
00227     if(m_custom.size())
00228      remove(name, m_custom);
00229    erase(name, m_base);
00230   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::DeviceInputs::renameData ( Inputs inputs,
const std::string &  old_name,
const std::string &  new_name 
) [private]

Definition at line 276 of file InputDevice.cpp.

References Logger::log_debug(), and Logger::log_error().

Referenced by setInput().

00276                                                                                                     {
00277     InputData* tmp_ptr = NULL;  
00278     Inputs::iterator i; 
00279 
00280     if( inputs.find(new_name) != inputs.end() ) {
00281       //log_error("renameData() tried to set name to pre-existing input"); 
00282       return false;
00283     }
00284     else if( ( (i = inputs.find(old_name)) == inputs.end()) ) {
00285       log_error("renameData() input to be renamed doesn't exist"); 
00286       return false;
00287     }
00288     else if(!(tmp_ptr= inputs[old_name])) {
00289       log_error("renameData() InputData found null at old_name"); 
00290       return false;
00291     }
00292 
00294     log_debug(std::string("setting data old name: ").append(old_name).append(" to: ").append(new_name));
00295 
00296     tmp_ptr -> setName(new_name);
00297 
00299     inputs.erase(inputs.find(old_name));
00300 
00302     std::pair<std::string, InputData* const> input_pair (new_name, tmp_ptr); 
00303     inputs.insert(input_pair);
00304 
00305     return true;
00306   }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long int cmil::DeviceInputs::resetIDs ( unsigned long int  count  ) 

Definition at line 261 of file InputDevice.cpp.

References Logger::log_debug(), and m_base.

Referenced by cmil::InputDevice::resetIDs().

00261                                                                     {
00262     log_debug("resetting base IDs");
00263     Inputs::iterator i;
00264     for(i = m_base.begin(); i != m_base.end(); ++i)  
00265       (i->second)->setID(count++);
00266 
00267     return count;
00268   }

Here is the call graph for this function:

Here is the caller graph for this function:

void cmil::DeviceInputs::resetWhichDevice ( unsigned long int  which_device  ) 

Definition at line 270 of file InputDevice.cpp.

References m_base.

Referenced by cmil::InputDevice::resetWhichDevice().

00270                                                                      {
00271     Inputs::iterator i;
00272     for(i = m_base.begin(); i != m_base.end(); ++i) 
00273       (i->second)->setWhichDevice(which_device);
00274   }

Here is the caller graph for this function:

bool cmil::DeviceInputs::setInput ( const std::string &  old_name,
const std::string &  new_name 
)

Definition at line 308 of file InputDevice.cpp.

References m_base, m_custom, and renameData().

Referenced by cmil::InputDevice::setInput(), and setInputs().

00308                                                                                   {
00309     if(!m_custom.size())
00310       m_custom = m_base;
00311 
00312     if( renameData(m_custom, old_name, new_name) )
00313       return true;
00314 
00315     //log_error("setInput() failed to rename input");
00316     return false;
00317   }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cmil::DeviceInputs::setInputs ( const DeviceInputs dev_inputs  ) 

Definition at line 232 of file InputDevice.cpp.

References getCustomInputs(), getInputs(), isEqual(), Logger::log_error(), m_custom, and setInput().

Referenced by cmil::InputDevice::setInputs().

00232                                                              {
00233     const bool match_base = false;
00234     std::string base_name, custom_name;
00235     Inputs::const_iterator i, i_custom;
00236 
00238     if( !(isEqual(match_base, dev_inputs)) ) {
00239       log_error("setInputs() This operation isn't allowed due to DeviceInputs base mismatch"); 
00240       return false;
00241     }
00242     else {
00243       if(dev_inputs.getInputs().size() != dev_inputs.getCustomInputs().size()) {
00244         log_error("setInputs() This operation isn't allowed due to a mismatch in size of parameter inputs."); 
00245         return false;
00246       }
00247     }
00248 
00250     m_custom.clear(); 
00251 
00254     
00255     for(i = dev_inputs.getInputs().begin(); i != dev_inputs.getInputs().end(); ++i) 
00256       setInput(i->first, i->second->getName());
00257 
00258     return true;
00259   }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Inputs cmil::DeviceInputs::m_base [private]

Inputs are only added to this container.

Definition at line 76 of file InputDevice.h.

Referenced by add(), cleanup(), clone(), DeviceInputs(), getData(), getInputs(), isEqual(), removeInput(), resetIDs(), resetWhichDevice(), and setInput().

Inputs cmil::DeviceInputs::m_custom [private]

Inputs are customized via this container.

Definition at line 79 of file InputDevice.h.

Referenced by clone(), DeviceInputs(), dumpInputs(), getCustomInputs(), getData(), isEqual(), removeInput(), setInput(), and setInputs().

const bool cmil::DeviceInputs::use_base = true [static]

These are here to reduce confusion.

Definition at line 41 of file InputDevice.h.

Referenced by cmil::SDL::SDLMice::assign_inputs(), and cmil::InputDevice::getData().

const bool cmil::DeviceInputs::use_custom = false [static]

Definition at line 42 of file InputDevice.h.

Referenced by cmil::DeviceRegistry::getData().


The documentation for this class was generated from the following files:
(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:03 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo