Blender  V2.93
ExtraTags.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_string.h"
22 #include <cstddef>
23 #include <cstdlib>
24 
25 #include <iostream>
26 
27 #include "ExtraTags.h"
28 
29 ExtraTags::ExtraTags(std::string profile)
30 {
31  this->profile = profile;
32  this->tags = std::map<std::string, std::string>();
33 }
34 
35 ExtraTags::~ExtraTags() = default;
36 
37 bool ExtraTags::isProfile(std::string profile)
38 {
39  return this->profile == profile;
40 }
41 
42 bool ExtraTags::addTag(std::string tag, std::string data)
43 {
44  tags[tag] = data;
45 
46  return true;
47 }
48 
49 int ExtraTags::asInt(std::string tag, bool *ok)
50 {
51  if (tags.find(tag) == tags.end()) {
52  *ok = false;
53  return -1;
54  }
55  *ok = true;
56  return atoi(tags[tag].c_str());
57 }
58 
59 float ExtraTags::asFloat(std::string tag, bool *ok)
60 {
61  if (tags.find(tag) == tags.end()) {
62  *ok = false;
63  return -1.0f;
64  }
65  *ok = true;
66  return (float)atof(tags[tag].c_str());
67 }
68 
69 std::string ExtraTags::asString(std::string tag, bool *ok)
70 {
71  if (tags.find(tag) == tags.end()) {
72  *ok = false;
73  return "";
74  }
75  *ok = true;
76  return tags[tag];
77 }
78 
79 bool ExtraTags::setData(std::string tag, short *data)
80 {
81  bool ok = false;
82  int tmp = asInt(tag, &ok);
83  if (ok) {
84  *data = (short)tmp;
85  }
86  return ok;
87 }
88 
89 bool ExtraTags::setData(std::string tag, int *data)
90 {
91  bool ok = false;
92  int tmp = asInt(tag, &ok);
93  if (ok) {
94  *data = tmp;
95  }
96  return ok;
97 }
98 
99 bool ExtraTags::setData(std::string tag, float *data)
100 {
101  bool ok = false;
102  float tmp = asFloat(tag, &ok);
103  if (ok) {
104  *data = tmp;
105  }
106  return ok;
107 }
108 
109 bool ExtraTags::setData(std::string tag, char *data)
110 {
111  bool ok = false;
112  int tmp = asInt(tag, &ok);
113  if (ok) {
114  *data = (char)tmp;
115  }
116  return ok;
117 }
118 
119 std::string ExtraTags::setData(std::string tag, std::string &data)
120 {
121  bool ok = false;
122  std::string tmp = asString(tag, &ok);
123  return (ok) ? tmp : data;
124 }
ExtraTags(const std::string profile)
Definition: ExtraTags.cpp:29
virtual ~ExtraTags()
bool isProfile(std::string profile)
Definition: ExtraTags.cpp:37
bool setData(std::string tag, short *data)
Definition: ExtraTags.cpp:79
bool addTag(std::string tag, std::string data)
Definition: ExtraTags.cpp:42