Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Source.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2022 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
25#ifndef SOURCE_H_
26#define SOURCE_H_
27
28#include <boost/variant.hpp>
29#include <memory>
30#include <string>
31#include <vector>
32
34
39
40namespace Euclid {
41namespace SourceCatalog {
42
48class Source {
49
50public:
51 typedef boost::variant<int64_t, std::string> id_type;
52
62
64 virtual ~Source() = default;
65
70 id_type getId() const {
71 return m_source_id;
72 }
73
87 template <typename T>
89
90private:
91 // Source identification
93
94 // Vector of shared pointers to attribute
96};
97// Eof class Source
98
105class CastSourceIdVisitor : public boost::static_visitor<Source::id_type> {
106 template <typename From>
107 static constexpr bool is_integer() {
109 }
110
111public:
113
115 return from;
116 }
117
118 template <typename From>
119 Source::id_type operator()(const From& from, typename std::enable_if<is_integer<From>()>::type* = 0) const {
120 return Source::id_type(static_cast<int64_t>(from));
121 }
122
123 template <typename From>
124 Source::id_type operator()(const From&, typename std::enable_if<!is_integer<From>()>::type* = 0) const {
125 throw Elements::Exception() << "Only std::string and int64_t are supported types for a source ID, got "
126 << typeid(From).name() << " instead";
127 }
128};
129
130#define SOURCE_IMPL
132#undef SOURCE_IMPL
133
134} /* namespace SourceCatalog */
135} // end of namespace Euclid
136
137#if BOOST_VERSION < 105800
138namespace boost {
139
147 return !(a == b);
148}
149
150} // namespace boost
151#endif
152
153#endif /* SOURCE_H_ */
This type can be used together with boost::apply_visitor to cast boost::variant with an unknown under...
Definition Source.h:105
Source::id_type operator()(const From &, typename std::enable_if<!is_integer< From >()>::type *=0) const
Definition Source.h:124
static constexpr bool is_integer()
Definition Source.h:107
Source::id_type operator()(const std::string &from) const
Definition Source.h:114
Source::id_type operator()(const From &from, typename std::enable_if< is_integer< From >()>::type *=0) const
Definition Source.h:119
Store the Right Ascension (Ra) and Delination (Dec) of a source in decimal degrees,...
Definition Coordinates.h:41
The Source class includes all information related to a sky source.
Definition Source.h:48
virtual ~Source()=default
Virtual default destructor.
std::shared_ptr< T > getAttribute() const
Get a pointer to source attribute of type T or a null pointer if the source do not contain an attribu...
Source(id_type source_id, std::vector< std::shared_ptr< Attribute > > attributeVector)
Constructor.
Definition Source.h:60
id_type getId() const
Get the source ID.
Definition Source.h:70
std::vector< std::shared_ptr< Attribute > > m_attribute_vector
Definition Source.h:95
boost::variant< int64_t, std::string > id_type
Definition Source.h:51
Definition array.h:33
bool operator!=(const Euclid::SourceCatalog::Source::id_type &a, const Euclid::SourceCatalog::Source::id_type &b)
boost::variant specifies an equality operator (==), but, in older boost versions, not an inequality o...
Definition Source.h:145
STL namespace.