Alexandria  2.16
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Catalog.cpp
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 
27 #include "SourceCatalog/Catalog.h"
28 #include "SourceCatalog/Source.h"
29 
31 
32 using namespace std;
33 
34 namespace Euclid {
35 namespace SourceCatalog {
36 
37 //-----------------------------------------------------------------------------
38 // Constructor
39 Catalog::Catalog(vector<Source> source_vector): m_source_vector(source_vector)
40 {
41  // Set the m_indices_map map
42  for (size_t index=0; index < m_source_vector.size(); ++index) {
43  auto it = m_source_index_map.emplace(m_source_vector[index].getId(), index);
44  // Make sure the element does not already exist
45  if (!it.second)
46  {
47  throw Elements::Exception() << "Euclid::SourceCatalog::Catalog: Source object already exist "
48  << "in the map for source ID : " << m_source_vector[index].getId() << ", index: " << index;
49  }
50  }
51 } // Eof Euclid::SourceCatalog::Catalog
52 
53 
54 //-----------------------------------------------------------------------------
55 // find source in the map
56 // return source otherwise null pointer
58 {
59  shared_ptr<Source> ptr(nullptr);
60  auto it = m_source_index_map.find(source_id);
61  if (it != m_source_index_map.end()) {
62  ptr = make_shared<Source>(m_source_vector[it->second]);
63  }
64 
65  return (ptr);
66 
67 } // Eof Catalog::find
68 
69 //-----------------------------------------------------------------------------
70 
71 } /* namespace SourceCatalog */
72 } // end of namespace Euclid
boost::variant< int64_t, std::string > id_type
Definition: Source.h:51
std::map< Source::id_type, size_t > m_source_index_map
Definition: Catalog.h:118
std::vector< Source > m_source_vector
Definition: Catalog.h:115
STL class.
std::shared_ptr< Source > find(const Source::id_type &source_id) const
Find the Source object from its identification number.
Definition: Catalog.cpp:57