Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
QualifiedName.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
27#include <algorithm>
28#include <boost/algorithm/string.hpp>
29
30namespace Euclid {
31namespace XYDataset {
32
34 : m_groups{std::move(groups_)}, m_dataset_name{std::move(name)} {
35 for (auto& group : m_groups) {
36 if (group.empty() || group.find('/') != std::string::npos) {
37 throw Elements::Exception() << "Invalid group name : \"" << group << "\""
38 << " in qualified name : \"" << m_qualified_name.append(group).append("/") << "\"";
39 }
40 m_qualified_name.append(group).append("/");
41 }
42 if (m_dataset_name.empty() || m_dataset_name.find('/') != std::string::npos) {
43 throw Elements::Exception() << "Invalid name : \"" << m_qualified_name.append(m_dataset_name) << "\"";
44 }
46}
47
50 boost::split(groups, qualified_name, boost::is_any_of("/"));
51 // The last one is the name, so we remove it
52 groups.pop_back();
53 return groups;
54}
55
56std::string getName(const std::string& qualified_name) {
58 boost::split(groups, qualified_name, boost::is_any_of("/"));
59 return groups.back();
60}
61
63 : QualifiedName(getGroups(qualified_name), getName(qualified_name)) {}
64
68
72
76
78 if (group.m_groups.size() + 1 > this->m_groups.size()) {
79 return false;
80 }
81 bool group_check = std::equal(group.m_groups.begin(), group.m_groups.end(), this->m_groups.begin());
82 return group_check ? group.m_dataset_name == this->m_groups.at(group.m_groups.size()) : false;
83}
84
85size_t QualifiedName::hash() const {
86 if (m_hash == 0) {
87 std::hash<std::string> stringHash;
88 m_hash = stringHash(qualifiedName());
89 }
90 return m_hash;
91}
92
93bool QualifiedName::operator<(const QualifiedName& other) const {
94 size_t thisHash = this->hash();
95 size_t otherHash = other.hash();
96 if (thisHash != otherHash) {
97 return thisHash < otherHash;
98 } else {
99 return this->qualifiedName() < other.qualifiedName();
100 }
101}
102
103bool QualifiedName::operator==(const QualifiedName& other) const {
104 size_t thisHash = this->hash();
105 size_t otherHash = other.hash();
106 if (thisHash != otherHash) {
107 return false;
108 } else {
109 return this->qualifiedName() == other.qualifiedName();
110 }
111}
112
113bool QualifiedName::operator!=(const QualifiedName& other) const {
114 return !(*this == other);
115}
116
117std::ostream& operator<<(std::ostream& stream, const QualifiedName& qualified_name) {
118 stream << qualified_name.qualifiedName();
119 return stream;
120}
121
122} // namespace XYDataset
123} // end of namespace Euclid
T append(T... args)
T at(T... args)
T begin(T... args)
Represents a name qualified with a set of groups.
bool operator==(const QualifiedName &other) const
Checks if this QualifiedName is equal with the parameter.
size_t hash() const
Returns the hash value of the QualifiedName.
bool belongsInGroup(const QualifiedName &group) const
Checks if the QualifiedName belongs in a given group.
bool operator<(const QualifiedName &other) const
Compares this QualifiedName with the parameter.
const std::string & qualifiedName() const
Returns the qualified name as a string.
const std::string & datasetName() const
Returns the unqualified name.
const std::vector< std::string > & groups() const
Returns the groups qualifying the name.
std::vector< std::string > m_groups
bool operator!=(const QualifiedName &other) const
Checks if this QualifiedName is not equal with the parameter.
QualifiedName(std::vector< std::string > groups, std::string name)
Constructs a QualifiedName with the given group and name.
T empty(T... args)
T end(T... args)
T equal(T... args)
T find(T... args)
std::string getName(const std::string &qualified_name)
std::vector< std::string > getGroups(const std::string &qualified_name)
STL namespace.
T size(T... args)