Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
DataSet.cxx
1/*
2 *
3 * This file is part of Tulip (https://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
22template <typename T>
23bool tlp::DataSet::get(const std::string &str, T &value) const {
24 const std::string &key = getUsedName(str);
25 for (std::list<std::pair<std::string, tlp::DataType *>>::const_iterator it = data.begin();
26 it != data.end(); ++it) {
27 if (it->first == key) {
28 value = *(static_cast<T *>(it->second->value));
29 return true;
30 }
31 }
32
33 return false;
34}
35
36// DataSet implementation
37template <typename T>
38bool tlp::DataSet::getDeprecated(const std::string &key, const std::string &oldKey,
39 T &value) const {
40 bool found = false;
41 for (std::list<std::pair<std::string, tlp::DataType *>>::const_iterator it = data.begin();
42 it != data.end(); ++it) {
43 // as 'this' DataSet may have been initialized
44 // using ParametersDescriptionList::buildDefaultDataSet
45 // key and oldKey may be present
46 // so check oldKey first
47 if (it->first == oldKey) {
48 tlp::warning() << "Warning: '" << oldKey.c_str() << "' is a deprecated DataSet key. Use '"
49 << key.c_str() << "' instead." << std::endl;
50 value = *(static_cast<T *>(it->second->value));
51 return true;
52 }
53 if (it->first == key) {
54 value = *(static_cast<T *>(it->second->value));
55 found = true;
56 }
57 }
58 return found;
59}
60
61template <typename T>
62bool tlp::DataSet::getAndFree(const std::string &str, T &value) {
63 const std::string &key = getUsedName(str);
64 for (std::list<std::pair<std::string, tlp::DataType *>>::iterator it = data.begin();
65 it != data.end(); ++it) {
66
67 if (it->first == key) {
68 value = *(static_cast<T *>(it->second->value));
69 delete it->second;
70 data.erase(it);
71 return true;
72 }
73 }
74
75 return false;
76}
77
78template <typename T>
79void tlp::DataSet::set(const std::string &key, const T &value) {
80 TypedData<T> dtc(new T(value));
81 setData(key, &dtc);
82}
83
84template <typename T>
85void tlp::DataSet::setDeprecated(const std::string &key, const std::string &oldKey,
86 const T &value) {
87 TypedData<T> dtc(new T(value));
88 setData(key, &dtc);
89 addDeprecated(oldKey, key);
90}
91//=======================================================================
bool getDeprecated(const std::string &key, const std::string &oldKey, T &value) const
Returns the stored value associated with the given key or the deprecated version of the key The store...
Definition: DataSet.cxx:38
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:79
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:62
void setDeprecated(const std::string &key, const std::string &deprecatedKey, const T &value)
Stores a copy of the given param, associated with a key and a deprected version of the key The value ...
Definition: DataSet.cxx:85