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