SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
taginfo.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5#include "vsitags.hpp"
6#include "vsistruct.hpp"
7#include <list>
8#include <algorithm>
9
10namespace slideio
11{
12 namespace vsi
13 {
14 class TagInfo
15 {
16 public:
17 TagInfo(TagInfo&& other) noexcept
18 : tag(other.tag),
19 fieldType(other.fieldType),
20 valueType(other.valueType),
21 extendedType(other.extendedType),
22 secondTag(other.secondTag),
23 extended(other.extended),
24 dataSize(other.dataSize),
25 name(std::move(other.name)),
26 children(std::move(other.children)),
27 value(std::move(other.value)) {
28 }
29
30 TagInfo& operator=(TagInfo&& other) noexcept {
31 if (this == &other)
32 return *this;
33 tag = other.tag;
34 fieldType = other.fieldType;
35 valueType = other.valueType;
36 extendedType = other.extendedType;
37 secondTag = other.secondTag;
38 extended = other.extended;
39 dataSize = other.dataSize;
40 name = std::move(other.name);
41 children = std::move(other.children);
42 value = std::move(other.value);
43 return *this;
44 }
45 ~TagInfo() = default;
46
47 typedef std::list<TagInfo> TagInfos;
48 typedef TagInfos::const_iterator const_iterator;
49 typedef TagInfos::iterator iterator;
50 TagInfo() = default;
51 TagInfo(const TagInfo& other) {
52 copy(other);
53 }
54 TagInfo& operator=(const TagInfo& other) {
55 copy(other);
56 return *this;
57 }
58 iterator end() { return children.end(); }
59 iterator begin() { return children.begin(); }
60 const_iterator end() const { return children.end(); }
61 const_iterator begin() const { return children.begin(); }
62 const_iterator find(int tag) {
63 return std::find_if(children.begin(), children.end(), [tag](const TagInfo& info) {
64 return info.tag == tag;
65 });
66 }
67 void addChild(const TagInfo& info) {
68 children.push_back(info);
69 }
70 void setValue(const std::string& srcValue) {
71 this->value = srcValue;
72 }
73 void copy(const TagInfo& other) {
74 tag = other.tag;
75 fieldType = other.fieldType;
76 valueType = other.valueType;
77 extendedType = other.extendedType;
78 secondTag = other.secondTag;
79 extended = other.extended;
80 dataSize = other.dataSize;
81 name = other.name;
82 value = other.value;
83 children.assign(other.children.begin(), other.children.end());
84 }
85 bool empty() const {
86 return children.empty();
87 }
88 const TagInfo* findChild(int srcTag) const {
89 auto it = std::find_if(children.begin(), children.end(), [srcTag](const TagInfo& info) {
90 return info.tag == srcTag;
91 });
92 if (it == children.end()) {
93 return nullptr;
94 }
95 return &(*it);
96 }
97 const_iterator findNextChild(int srcTag, const_iterator begin) const {
98 return std::find_if(begin, children.end(), [srcTag](const TagInfo& info) {
99 return info.tag == srcTag;
100 });
101 }
102 const vsi::TagInfo* findChild(const std::vector<int>& path) const {
103 const TagInfo* current = this;
104 for (const int srcTag : path) {
105 current = current->findChild(srcTag);
106 if (!current) {
107 break;
108 }
109 }
110 return current;
111 }
112
113 const vsi::TagInfo* findChildRecursively(const int tag) const {
114 for (auto& child : children) {
115 if (child.tag == tag) {
116 return &child;
117 }
118 if (const TagInfo* found = child.findChildRecursively(tag)) {
119 return found;
120 }
121 }
122 return nullptr;
123 }
124 public:
125 int tag = Tag::UNKNOWN;
126 int fieldType = 0;
127 ValueType valueType = ValueType::UNSET;
128 ExtendedType extendedType = ExtendedType::UNSET;
129 int secondTag = -1;
130 bool extended = false;
131 int32_t dataSize = 0;
132 std::string name;
133 TagInfos children;
134 std::string value;
135 };
136 }
137}
Definition: exceptions.hpp:15