Leosac  0.8.0
Open Source Access Control
bs2.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include <boost/signals2.hpp>
23 
24 namespace Leosac
25 {
29 namespace bs2 = boost::signals2;
30 
34 template <typename T>
36 {
37  using result_type = std::vector<T>;
38 
39  template <typename InputIterator>
40  std::vector<T> operator()(InputIterator first, InputIterator last) const
41  {
42  std::vector<T> result;
43  if (first == last)
44  return {};
45 
46  while (first != last)
47  {
48  std::vector<T> this_slot_result = *first;
49  result.insert(result.end(), this_slot_result.begin(),
50  this_slot_result.end());
51  ++first;
52  }
53  return result;
54  }
55 };
56 
63 template <typename T>
65 {
66  using result_type = T;
67 
68  template <typename InputIterator>
69  T operator()(InputIterator first, InputIterator last) const
70  {
71  bool set = false;
72  T result = nullptr;
73  if (first == last)
74  return T{};
75 
76  while (first != last)
77  {
78  T tmp = nullptr;
79  tmp = *first;
80 
81  if (tmp && set)
82  {
83  throw LEOSACException("AtMostOneCombiner: A non-null pointer has "
84  "already been returned.");
85  }
86  else if (tmp)
87  {
88  result = tmp;
89  set = true;
90  }
91 
92  ++first;
93  }
94  return result;
95  }
96 };
97 }
Leosac::AtMostOneCombiner::operator()
T operator()(InputIterator first, InputIterator last) const
Definition: bs2.hpp:69
Leosac::AtMostOneCombiner::result_type
T result_type
Definition: bs2.hpp:66
set
set(OdbCMake_ODB_HEADERS_TOOLS ${CMAKE_SOURCE_DIR}/src/tools/LogEntry.hpp ${CMAKE_SOURCE_DIR}/src/tools/SingleTimeFrame.hpp ${CMAKE_SOURCE_DIR}/src/tools/Schedule.hpp ${CMAKE_SOURCE_DIR}/src/tools/ScheduleMapping.hpp ${CMAKE_SOURCE_DIR}/src/tools/Uuid.hpp) set(LEOSAC_ODB_INCLUDE_DIRS $
Definition: CMakeLists.txt:12
Leosac::VectorAppenderCombiner::operator()
std::vector< T > operator()(InputIterator first, InputIterator last) const
Definition: bs2.hpp:40
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::AtMostOneCombiner
A boost::signals2 combiner that makes sure that at most one slot returns a non-null pointer.
Definition: bs2.hpp:64
Leosac::VectorAppenderCombiner
A shortname for the boost::signals2 namespace.
Definition: bs2.hpp:35
LEOSACException
A base class for Leosac specific exception.
Definition: leosacexception.hpp:40
Leosac::VectorAppenderCombiner::result_type
std::vector< T > result_type
Definition: bs2.hpp:37