Blender  V3.3
ExtraTags.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_string.h"
8 #include <cstddef>
9 #include <cstdlib>
10 
11 #include <iostream>
12 
13 #include "ExtraTags.h"
14 
15 ExtraTags::ExtraTags(std::string profile)
16 {
17  this->profile = profile;
18  this->tags = std::map<std::string, std::string>();
19 }
20 
21 ExtraTags::~ExtraTags() = default;
22 
23 bool ExtraTags::isProfile(std::string profile)
24 {
25  return this->profile == profile;
26 }
27 
28 bool ExtraTags::addTag(std::string tag, std::string data)
29 {
30  tags[tag] = data;
31 
32  return true;
33 }
34 
35 int ExtraTags::asInt(std::string tag, bool *ok)
36 {
37  if (tags.find(tag) == tags.end()) {
38  *ok = false;
39  return -1;
40  }
41  *ok = true;
42  return atoi(tags[tag].c_str());
43 }
44 
45 float ExtraTags::asFloat(std::string tag, bool *ok)
46 {
47  if (tags.find(tag) == tags.end()) {
48  *ok = false;
49  return -1.0f;
50  }
51  *ok = true;
52  return (float)atof(tags[tag].c_str());
53 }
54 
55 std::string ExtraTags::asString(std::string tag, bool *ok)
56 {
57  if (tags.find(tag) == tags.end()) {
58  *ok = false;
59  return "";
60  }
61  *ok = true;
62  return tags[tag];
63 }
64 
65 bool ExtraTags::setData(std::string tag, short *data)
66 {
67  bool ok = false;
68  int tmp = asInt(tag, &ok);
69  if (ok) {
70  *data = (short)tmp;
71  }
72  return ok;
73 }
74 
75 bool ExtraTags::setData(std::string tag, int *data)
76 {
77  bool ok = false;
78  int tmp = asInt(tag, &ok);
79  if (ok) {
80  *data = tmp;
81  }
82  return ok;
83 }
84 
85 bool ExtraTags::setData(std::string tag, float *data)
86 {
87  bool ok = false;
88  float tmp = asFloat(tag, &ok);
89  if (ok) {
90  *data = tmp;
91  }
92  return ok;
93 }
94 
95 bool ExtraTags::setData(std::string tag, char *data)
96 {
97  bool ok = false;
98  int tmp = asInt(tag, &ok);
99  if (ok) {
100  *data = (char)tmp;
101  }
102  return ok;
103 }
104 
105 std::string ExtraTags::setData(std::string tag, std::string &data)
106 {
107  bool ok = false;
108  std::string tmp = asString(tag, &ok);
109  return (ok) ? tmp : data;
110 }
ExtraTags(const std::string profile)
Definition: ExtraTags.cpp:15
virtual ~ExtraTags()
bool isProfile(std::string profile)
Definition: ExtraTags.cpp:23
bool setData(std::string tag, short *data)
Definition: ExtraTags.cpp:65
bool addTag(std::string tag, std::string data)
Definition: ExtraTags.cpp:28