Alexandria
2.16
Please provide a description of the project.
SourceCatalog
SourceCatalog
Source.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012-2020 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 <string>
29
#include <vector>
30
#include <memory>
31
#include <boost/variant.hpp>
32
33
#include "
ElementsKernel/Exception.h
"
34
35
#include "
SourceCatalog/SourceAttributes/Photometry.h
"
36
#include "
SourceCatalog/SourceAttributes/SpectroscopicRedshift.h
"
37
#include "
SourceCatalog/SourceAttributes/Coordinates.h
"
38
#include "
SourceCatalog/Attribute.h
"
39
40
namespace
Euclid
{
41
namespace
SourceCatalog {
42
48
class
Source
{
49
50
public
:
51
typedef
boost::variant<int64_t, std::string>
id_type
;
52
60
Source
(
id_type
source_id,
std::vector
<
std::shared_ptr<Attribute>
> attributeVector)
61
:
m_source_id
(source_id),
m_attribute_vector
(
std
::move(attributeVector) ) {
62
}
63
65
virtual
~Source
() { }
66
71
id_type
getId
()
const
{
72
return
m_source_id
;
73
}
74
88
template
<
typename
T>
89
std::shared_ptr<T>
getAttribute
()
const
;
90
91
92
private
:
93
94
// Source identification
95
id_type
m_source_id
{ };
96
97
// Vector of shared pointers to attribute
98
std::vector<std::shared_ptr<Attribute>
>
m_attribute_vector
;
99
100
};
101
// Eof class Source
102
109
class
CastSourceIdVisitor
:
public
boost::static_visitor<Source::id_type> {
110
template
<
typename
From>
111
static
constexpr
bool
is_integer
() {
112
return
std::is_integral<From>::value
&& !
std::is_same<From, bool>::value
;
113
}
114
115
public
:
116
CastSourceIdVisitor
() {}
117
118
Source::id_type
operator()
(
const
std::string
&from)
const
{
119
return
from;
120
}
121
122
template
<
typename
From>
123
Source::id_type
operator()
(
const
From &from,
typename
std::enable_if
<is_integer<From>()>::type* = 0)
const
{
124
return
Source::id_type
(
static_cast<
int64_t
>
(from));
125
}
126
127
template
<
typename
From>
128
Source::id_type
operator()
(
const
From &,
typename
std::enable_if
<!is_integer<From>()>::type* = 0)
const
{
129
throw
Elements::Exception
() <<
"Only std::string and int64_t are supported types for a source ID, got "
130
<<
typeid
(From).name() <<
" instead"
;
131
}
132
};
133
134
#define SOURCE_IMPL
135
#include "
SourceCatalog/_impl/Source.icpp
"
136
#undef SOURCE_IMPL
137
138
}
/* namespace SourceCatalog */
139
}
// end of namespace Euclid
140
141
#if BOOST_VERSION < 105800
142
namespace
boost
{
143
149
inline
bool
operator!=
(
const
Euclid::SourceCatalog::Source::id_type
& a,
const
Euclid::SourceCatalog::Source::id_type
& b) {
150
return
!(a == b);
151
}
152
153
}
154
#endif
155
156
#endif
/* SOURCE_H_ */
Coordinates.h
std::is_same
std::string
STL class.
std::shared_ptr
STL class.
Euclid::SourceCatalog::CastSourceIdVisitor::operator()
Source::id_type operator()(const std::string &from) const
Definition:
Source.h:118
std::vector
STL class.
Photometry.h
Euclid::SourceCatalog::Source::Source
Source(id_type source_id, std::vector< std::shared_ptr< Attribute >> attributeVector)
Constructor.
Definition:
Source.h:60
boost::operator!=
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:149
boost
Definition:
array.h:34
Euclid::SourceCatalog::Source::getAttribute
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...
Euclid::SourceCatalog::Source::getId
id_type getId() const
Get the source ID.
Definition:
Source.h:71
std::enable_if
Euclid::SourceCatalog::Source::m_source_id
id_type m_source_id
Definition:
Source.h:95
Euclid::SourceCatalog::CastSourceIdVisitor::CastSourceIdVisitor
CastSourceIdVisitor()
Definition:
Source.h:116
Exception.h
Elements::Exception
Euclid::SourceCatalog::Source::m_attribute_vector
std::vector< std::shared_ptr< Attribute > > m_attribute_vector
Definition:
Source.h:98
Euclid::SourceCatalog::CastSourceIdVisitor::is_integer
static constexpr bool is_integer()
Definition:
Source.h:111
std::is_integral
Euclid::SourceCatalog::Source
The Source class includes all information related to a sky source.
Definition:
Source.h:48
SpectroscopicRedshift.h
Source.icpp
std
STL namespace.
Euclid::SourceCatalog::Source::id_type
boost::variant< int64_t, std::string > id_type
Definition:
Source.h:51
Euclid::SourceCatalog::Source::~Source
virtual ~Source()
Virtual default destructor.
Definition:
Source.h:65
Euclid::SourceCatalog::CastSourceIdVisitor
This type can be used together with boost::apply_visitor to cast boost::variant with an unknown under...
Definition:
Source.h:109
Euclid
Definition:
InstOrRefHolder.h:29
Attribute.h
Generated by
1.8.18