Blender V4.3
ExtraTags.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2002-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_string.h"
10#include <cstddef>
11#include <cstdlib>
12
13#include <iostream>
14#include <regex>
15
16#include "ExtraTags.h"
17
18ExtraTags::ExtraTags(std::string profile)
19{
20 this->profile = profile;
21 this->tags = std::map<std::string, std::string>();
22}
23
24ExtraTags::~ExtraTags() = default;
25
26bool ExtraTags::isProfile(std::string profile)
27{
28 return this->profile == profile;
29}
30
31bool ExtraTags::addTag(std::string tag, std::string data)
32{
33 tags[tag] = data;
34
35 return true;
36}
37
38int ExtraTags::asInt(std::string tag, bool *r_ok)
39{
40 if (tags.find(tag) == tags.end()) {
41 *r_ok = false;
42 return -1;
43 }
44 *r_ok = true;
45 return atoi(tags[tag].c_str());
46}
47
48float ExtraTags::asFloat(std::string tag, bool *r_ok)
49{
50 if (tags.find(tag) == tags.end()) {
51 *r_ok = false;
52 return -1.0f;
53 }
54 *r_ok = true;
55 return float(atof(tags[tag].c_str()));
56}
57
58std::string ExtraTags::asString(std::string tag, bool *r_ok)
59{
60 if (tags.find(tag) == tags.end()) {
61 *r_ok = false;
62 return "";
63 }
64 *r_ok = true;
65 return tags[tag];
66}
67
68bool ExtraTags::setData(std::string tag, short *data)
69{
70 bool ok = false;
71 int tmp = asInt(tag, &ok);
72 if (ok) {
73 *data = short(tmp);
74 }
75 return ok;
76}
77
78bool ExtraTags::setData(std::string tag, int *data)
79{
80 bool ok = false;
81 int tmp = asInt(tag, &ok);
82 if (ok) {
83 *data = tmp;
84 }
85 return ok;
86}
87
88bool ExtraTags::setData(std::string tag, float *data)
89{
90 bool ok = false;
91 float tmp = asFloat(tag, &ok);
92 if (ok) {
93 *data = tmp;
94 }
95 return ok;
96}
97
98bool ExtraTags::setData(std::string tag, char *data)
99{
100 bool ok = false;
101 int tmp = asInt(tag, &ok);
102 if (ok) {
103 *data = char(tmp);
104 }
105 return ok;
106}
107
108std::string ExtraTags::setData(std::string tag, std::string &data)
109{
110 bool ok = false;
111 std::string tmp = asString(tag, &ok);
112 return (ok) ? tmp : data;
113}
114
115std::vector<std::string> ExtraTags::dataSplitString(const std::string &tag)
116{
117 bool ok = false;
118 const std::string value = asString(tag, &ok);
119 if (!ok) {
120 return std::vector<std::string>();
121 }
122
123 std::vector<std::string> values;
124
125 const std::regex newline_re("[^\\s][^\\r\\n]+");
126 const std::sregex_token_iterator end;
127 std::sregex_token_iterator iter(value.begin(), value.end(), newline_re);
128 for (; iter != end; iter++) {
129 values.push_back(*iter);
130 }
131
132 return values;
133}
ExtraTags(const std::string profile)
Definition ExtraTags.cpp:18
virtual ~ExtraTags()
bool isProfile(std::string profile)
Definition ExtraTags.cpp:26
std::vector< std::string > dataSplitString(const std::string &tag)
bool setData(std::string tag, short *data)
Definition ExtraTags.cpp:68
bool addTag(std::string tag, std::string data)
Definition ExtraTags.cpp:31
draw_view in_light_buf[] float