Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
DataSet.cxx
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 //=======================================================================
21 //DataSet implementation
22 template<typename T> bool tlp::DataSet::get(const std::string& str,T& value) const {
23  for (std::list< std::pair<std::string, tlp::DataType*> >::const_iterator it =
24  data.begin(); it != data.end(); ++it) {
25  const std::pair<std::string, tlp::DataType*> &p = *it;
26 
27  if (p.first == str) {
28  value = *((T*) p.second->value);
29  return true;
30  }
31  }
32 
33  return false;
34 }
35 
36 template<typename T> bool tlp::DataSet::getAndFree(const std::string &str,T& value) {
37  for (std::list< std::pair<std::string, tlp::DataType*> >::iterator it =
38  data.begin(); it != data.end(); ++it) {
39  std::pair<std::string, tlp::DataType *> &p = *it;
40 
41  if (p.first == str) {
42  value = *((T*) p.second->value);
43  delete p.second;
44  data.erase(it);
45  return true;
46  }
47  }
48 
49  return false;
50 }
51 
52 template<typename T> void tlp::DataSet::set(const std::string &key,
53  const T& value) {
54  TypedData<T> dtc(new T(value));
55  setData(key, &dtc);
56 }
57 //=======================================================================