libpniio
get_children.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2013 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio 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 General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 // Created on: Jul 1, 2013
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 #pragma once
23 
24 #include "../nxobject_traits.hpp"
25 #include "object_predicates.hpp"
26 #include "iterators.hpp"
27 
28 namespace pni{
29 namespace io{
30 namespace nx{
31 
32 
33  template<
34  typename CTYPE,
35  typename OTYPE
36  >
37  void get_children(const OTYPE &p,const string &c,CTYPE &container)
38  {
39  typedef decltype(get_parent(p)) object_type;
40 
41  object_type parent(p); //whatever OTYPE is we go here for an object
42  //type
43 
44  //check if the parent is a group instance and throw an exception
45  //if otherwise
46  if(!is_group(parent))
47  throw type_error(EXCEPTION_RECORD,
48  "The parent object must be a group!");
49 
50  //iterate over all children
51  for(auto iter = begin(parent); iter!=end(parent);++iter)
52  {
53  //shortcut evaluation - if is_group is false the class
54  //is not checked
55  if(is_group(*iter) && is_class(*iter,c))
56  container.push_back(*iter);
57  }
58 
59  }
60 
87  template<
88  typename CTYPE,
89  typename OTYPE
90  >
91  CTYPE get_children(const OTYPE &parent,const string &c)
92  {
93  CTYPE container;
94 
95  get_children(parent,c,container);
96 
97  return container;
98  }
99 
100 
101 //end of namespace
102 }
103 }
104 }
void get_children(const OTYPE &p, const string &c, CTYPE &container)
Definition: get_children.hpp:37
Definition: cbf_reader.hpp:41
auto begin(const OTYPE< IMPID > &group) -> decltype(group.begin())
get iterator to first element
Definition: iterators.hpp:46
auto end(const OTYPE< IMPID > &group) -> decltype(group.end())
get iterator to last element
Definition: iterators.hpp:69
nxobject_trait< IMPID >::object_type get_parent(const OTYPE< IMPID > &o)
return parent
Definition: get_parent.hpp:53
bool is_class(const OTYPE< IMPID > &object, const pni::core::string &type)
checks group type
Definition: is_class.hpp:58
bool is_group(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o) noexcept
test for group
Definition: is_group.hpp:136