Alexandria  2.16
Please provide a description of the project.
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 
34 
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 
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>
90 
91 
92  private:
93 
94  // Source identification
96 
97  // Vector of shared pointers to attribute
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() {
113  }
114 
115 public:
117 
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
136 #undef SOURCE_IMPL
137 
138 } /* namespace SourceCatalog */
139 } // end of namespace Euclid
140 
141 #if BOOST_VERSION < 105800
142 namespace boost {
143 
150  return !(a == b);
151 }
152 
153 }
154 #endif
155 
156 #endif /* SOURCE_H_ */
boost::variant< int64_t, std::string > id_type
Definition: Source.h:51
Definition: array.h:34
Source(id_type source_id, std::vector< std::shared_ptr< Attribute >> attributeVector)
Constructor.
Definition: Source.h:60
virtual ~Source()
Virtual default destructor.
Definition: Source.h:65
This type can be used together with boost::apply_visitor to cast boost::variant with an unknown under...
Definition: Source.h:109
STL namespace.
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
STL class.
std::vector< std::shared_ptr< Attribute > > m_attribute_vector
Definition: Source.h:98
Source::id_type operator()(const std::string &from) const
Definition: Source.h:118
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...
The Source class includes all information related to a sky source.
Definition: Source.h:48
STL class.
id_type getId() const
Get the source ID.
Definition: Source.h:71
static constexpr bool is_integer()
Definition: Source.h:111