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
9namespace slideio
10{
11 namespace vsi
12 {
13 class TagInfo
14 {
15 public:
16 TagInfo(TagInfo&& other) noexcept
17 : tag(other.tag),
18 fieldType(other.fieldType),
19 valueType(other.valueType),
20 extendedType(other.extendedType),
21 secondTag(other.secondTag),
22 extended(other.extended),
23 dataSize(other.dataSize),
24 name(std::move(other.name)),
25 children(std::move(other.children)),
26 value(std::move(other.value)) {
27 }
28
29 TagInfo& operator=(TagInfo&& other) noexcept {
30 if (this == &other)
31 return *this;
32 tag = other.tag;
33 fieldType = other.fieldType;
34 valueType = other.valueType;
35 extendedType = other.extendedType;
36 secondTag = other.secondTag;
37 extended = other.extended;
38 dataSize = other.dataSize;
39 name = std::move(other.name);
40 children = std::move(other.children);
41 value = std::move(other.value);
42 return *this;
43 }
44 ~TagInfo() = default;
45
46 typedef std::list<TagInfo> TagInfos;
47 typedef TagInfos::const_iterator const_iterator;
48 typedef TagInfos::iterator iterator;
49 TagInfo() = default;
50 TagInfo(const TagInfo& other) {
51 copy(other);
52 }
53 TagInfo& operator=(const TagInfo& other) {
54 copy(other);
55 return *this;
56 }
57 iterator end() { return children.end(); }
58 iterator begin() { return children.begin(); }
59 const_iterator end() const { return children.end(); }
60 const_iterator begin() const { return children.begin(); }
61 const_iterator find(int tag) {
62 return std::find_if(children.begin(), children.end(), [tag](const TagInfo& info) {
63 return info.tag == tag;
64 });
65 }
66 void addChild(const TagInfo& info) {
67 children.push_back(info);
68 }
69 void setValue(const std::string& srcValue) {
70 this->value = srcValue;
71 }
72 void copy(const TagInfo& other) {
73 tag = other.tag;
74 fieldType = other.fieldType;
75 valueType = other.valueType;
76 extendedType = other.extendedType;
77 secondTag = other.secondTag;
78 extended = other.extended;
79 dataSize = other.dataSize;
80 name = other.name;
81 value = other.value;
82 children.assign(other.children.begin(), other.children.end());
83 }
84 bool empty() const {
85 return children.empty();
86 }
87 const TagInfo* findChild(int srcTag) const {
88 auto it = std::find_if(children.begin(), children.end(), [srcTag](const TagInfo& info) {
89 return info.tag == srcTag;
90 });
91 if (it == children.end()) {
92 return nullptr;
93 }
94 return &(*it);
95 }
96 const_iterator findNextChild(int srcTag, const_iterator begin) const {
97 return std::find_if(begin, children.end(), [srcTag](const TagInfo& info) {
98 return info.tag == srcTag;
99 });
100 }
101 const vsi::TagInfo* findChild(const std::vector<int>& path) const {
102 const TagInfo* current = this;
103 for (const int srcTag : path) {
104 current = current->findChild(srcTag);
105 if (!current) {
106 break;
107 }
108 }
109 return current;
110 }
111 public:
112 int tag = Tag::UNKNOWN;
113 int fieldType = 0;
114 ValueType valueType = ValueType::UNSET;
115 ExtendedType extendedType = ExtendedType::UNSET;
116 int secondTag = -1;
117 bool extended = false;
118 int32_t dataSize = 0;
119 std::string name;
120 TagInfos children;
121 std::string value;
122 };
123 }
124}
Definition: exceptions.hpp:12