Tulip  4.10.0
Better Visualization Through Research
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
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 //=======================================================================
void set(const std::string &key, const T &value)
Stores a copy of the given param, associated with the key. The value must have a well-formed copy con...
Definition: DataSet.cxx:52
bool get(const std::string &key, T &value) const
Returns the stored value associated with the given key. The stored value is a copy of the original va...
Definition: DataSet.cxx:22
void setData(const std::string &str, const DataType *value)
Set from an untyped value.
bool getAndFree(const std::string &key, T &value)
Returns the stored value, and deletes the stored copy. If no value is found, nothing is deleted...
Definition: DataSet.cxx:36