libpniio
get_object.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 2, 2013
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 #pragma once
23 
24 #include <pni/core/types.hpp>
25 
26 #include "../nxpath/nxpath.hpp"
27 #include "get_parent.hpp"
28 #include "get_root.hpp"
29 #include "get_attribute.hpp"
30 #include "get_child.hpp"
31 #include "utils.hpp"
32 
33 namespace pni{
34 namespace io{
35 namespace nx{
36 
58  template<
59  typename OTYPE,
60  typename PATHT
61  >
62  auto get_object(const OTYPE &o,const PATHT &path)
63  ->decltype(get_parent(o))
64  {
65  typedef decltype(get_parent(o)) object_type;
66  object_type target = o;
67  nxpath p = get_path(path);
68 
69  //traverse over the path
70  for(auto element: p)
71  {
72  if(element.first =="/")
73  target = get_root(target);
74  else if (element.first == ".")
75  continue;
76  else if (element.first == "..")
77  target = get_parent(target);
78  else
79  target = get_child(target,element.first,element.second);
80  }
81 
82  //if an attribute was requested
83  if(!p.attribute().empty())
84  target = get_attribute(target,p.attribute());
85 
86  return target;
87  }
88 
89 
90 //end of namespace
91 }
92 }
93 }
Definition: cbf_reader.hpp:41
nxobject_trait< IMPID >::object_type get_attribute(const PTYPE< IMPID > &parent, const pni::core::string &name)
get attribute by name
Definition: get_attribute.hpp:59
auto get_child(const OTYPE &o, const pni::core::string &n, const pni::core::string &c="") -> decltype(get_parent(o))
get child by name and/or class
Definition: get_child.hpp:59
auto get_object(const OTYPE &o, const PATHT &path) -> decltype(get_parent(o))
retrieve an object from path
Definition: get_object.hpp:62
auto get_root(const OTYPE &p) -> decltype(get_parent(p))
get root
Definition: get_root.hpp:47
nxobject_trait< IMPID >::object_type get_parent(const OTYPE< IMPID > &o)
return parent
Definition: get_parent.hpp:53
Nexus path class.
Definition: nxpath/nxpath.hpp:60
pni::core::string get_path(const OTYPE< IMPID > &o)
get object path
Definition: get_path.hpp:59