Welcome to mirror list, hosted at ThFree Co, Russian Federation.

metadata.cc « metadata « draco « src « draco « draco « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 51b4e93a32893168fdf5a4c77372375ce543df37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2017 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "draco/metadata/metadata.h"

#include <utility>

namespace draco {

EntryValue::EntryValue(const EntryValue &value) {
  data_.resize(value.data_.size());
  memcpy(&data_[0], &value.data_[0], value.data_.size());
}

EntryValue::EntryValue(const std::string &value) {
  data_.resize(value.size());
  memcpy(&data_[0], &value[0], value.size());
}

template <>
bool EntryValue::GetValue(std::string *value) const {
  if (data_.empty()) {
    return false;
  }
  value->resize(data_.size());
  memcpy(&value->at(0), &data_[0], data_.size());
  return true;
}

Metadata::Metadata(const Metadata &metadata) {
  entries_.insert(metadata.entries_.begin(), metadata.entries_.end());
  for (const auto &sub_metadata_entry : metadata.sub_metadatas_) {
    std::unique_ptr<Metadata> sub_metadata =
        std::unique_ptr<Metadata>(new Metadata(*sub_metadata_entry.second));
    sub_metadatas_[sub_metadata_entry.first] = std::move(sub_metadata);
  }
}

void Metadata::AddEntryInt(const std::string &name, int32_t value) {
  AddEntry(name, value);
}

bool Metadata::GetEntryInt(const std::string &name, int32_t *value) const {
  return GetEntry(name, value);
}

void Metadata::AddEntryIntArray(const std::string &name,
                                const std::vector<int32_t> &value) {
  AddEntry(name, value);
}

bool Metadata::GetEntryIntArray(const std::string &name,
                                std::vector<int32_t> *value) const {
  return GetEntry(name, value);
}

void Metadata::AddEntryDouble(const std::string &name, double value) {
  AddEntry(name, value);
}

bool Metadata::GetEntryDouble(const std::string &name, double *value) const {
  return GetEntry(name, value);
}

void Metadata::AddEntryDoubleArray(const std::string &name,
                                   const std::vector<double> &value) {
  AddEntry(name, value);
}

bool Metadata::GetEntryDoubleArray(const std::string &name,
                                   std::vector<double> *value) const {
  return GetEntry(name, value);
}

void Metadata::AddEntryString(const std::string &name,
                              const std::string &value) {
  AddEntry(name, value);
}

bool Metadata::GetEntryString(const std::string &name,
                              std::string *value) const {
  return GetEntry(name, value);
}

void Metadata::AddEntryBinary(const std::string &name,
                              const std::vector<uint8_t> &value) {
  AddEntry(name, value);
}

bool Metadata::GetEntryBinary(const std::string &name,
                              std::vector<uint8_t> *value) const {
  return GetEntry(name, value);
}

bool Metadata::AddSubMetadata(const std::string &name,
                              std::unique_ptr<Metadata> sub_metadata) {
  auto sub_ptr = sub_metadatas_.find(name);
  // Avoid accidentally writing over a sub-metadata with the same name.
  if (sub_ptr != sub_metadatas_.end()) {
    return false;
  }
  sub_metadatas_[name] = std::move(sub_metadata);
  return true;
}

const Metadata *Metadata::GetSubMetadata(const std::string &name) const {
  auto sub_ptr = sub_metadatas_.find(name);
  if (sub_ptr == sub_metadatas_.end()) {
    return nullptr;
  }
  return sub_ptr->second.get();
}

Metadata *Metadata::sub_metadata(const std::string &name) {
  auto sub_ptr = sub_metadatas_.find(name);
  if (sub_ptr == sub_metadatas_.end()) {
    return nullptr;
  }
  return sub_ptr->second.get();
}

void Metadata::RemoveEntry(const std::string &name) {
  // Actually just remove "name", no need to check if it exists.
  auto entry_ptr = entries_.find(name);
  if (entry_ptr != entries_.end()) {
    entries_.erase(entry_ptr);
  }
}
}  // namespace draco