Tulip  5.2.1
Large graphs analysis and drawing
DataSet.cxx
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
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>
23 bool tlp::DataSet::get(const std::string &str, T &value) const {
24  for (std::list<std::pair<std::string, tlp::DataType *>>::const_iterator it = data.begin();
25  it != data.end(); ++it) {
26  const std::pair<std::string, tlp::DataType *> &p = *it;
27 
28  if (p.first == str) {
29  value = *(static_cast<T *>(p.second->value));
30  return true;
31  }
32  }
33 
34  return false;
35 }
36 
37 template <typename T>
38 bool tlp::DataSet::getAndFree(const std::string &str, T &value) {
39  for (std::list<std::pair<std::string, tlp::DataType *>>::iterator it = data.begin();
40  it != data.end(); ++it) {
41  std::pair<std::string, tlp::DataType *> &p = *it;
42 
43  if (p.first == str) {
44  value = *(static_cast<T *>(p.second->value));
45  delete p.second;
46  data.erase(it);
47  return true;
48  }
49  }
50 
51  return false;
52 }
53 
54 template <typename T>
55 void tlp::DataSet::set(const std::string &key, const T &value) {
56  TypedData<T> dtc(new T(value));
57  setData(key, &dtc);
58 }
59 //=======================================================================
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:23
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:55
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:38