Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/cxx/DataSet.cxx
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 
00020 //=======================================================================
00021 //DataSet implementation
00022 template<typename T> bool tlp::DataSet::get(const std::string& str,T& value) const {
00023   for (std::list< std::pair<std::string, tlp::DataType*> >::const_iterator it =
00024          data.begin(); it != data.end(); ++it) {
00025     const std::pair<std::string, tlp::DataType*> &p = *it;
00026 
00027     if (p.first == str) {
00028       value = *((T*) p.second->value);
00029       return true;
00030     }
00031   }
00032 
00033   return false;
00034 }
00035 
00036 template<typename T> bool tlp::DataSet::getAndFree(const std::string &str,T& value) {
00037   for (std::list< std::pair<std::string, tlp::DataType*> >::iterator it =
00038          data.begin(); it != data.end(); ++it) {
00039     std::pair<std::string, tlp::DataType *> &p = *it;
00040 
00041     if (p.first == str) {
00042       value = *((T*) p.second->value);
00043       delete p.second;
00044       data.erase(it);
00045       return true;
00046     }
00047   }
00048 
00049   return false;
00050 }
00051 
00052 template<typename T> void tlp::DataSet::set(const std::string &key,
00053     const T& value) {
00054   TypedData<T> dtc(new T(value));
00055   setData(key, &dtc);
00056 }
00057 //=======================================================================
 All Classes Files Functions Variables Enumerations Enumerator Properties