libpniio
xml/link.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2015 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: Apr 22, 2015
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 #pragma once
23 
24 #include "../algorithms/as_group.hpp"
25 #include "data_node.hpp"
26 #include "../nxlink.hpp"
27 
28 namespace pni{
29 namespace io{
30 namespace nx{
31 namespace xml{
32 
41 
42  class link
43  {
44  private:
55  static pni::core::string get_link_name(const node &link_node);
56 
57  //-----------------------------------------------------------------
68  static pni::core::string get_link_target(const node &link_node);
69 
70  public:
71 
95  template<
96  typename GTYPE,
97  typename FTYPE,
98  typename ATYPE,
99  typename LTYPE
100  >
101  static void object_from_xml(const nxobject<GTYPE,FTYPE,ATYPE,LTYPE> &parent,
102  const node &link_node);
103 
104  };
105 
106  //-------------------------------------------------------------------------
107  template<
108  typename GTYPE,
109  typename FTYPE,
110  typename ATYPE,
111  typename LTYPE
112  >
114  const node &link_node)
115  {
116  //will throw key error if name attribute does not exist
117  pni::core::string link_name = get_link_name(link_node);
118  //will thorw key_error if target attribute does not exist
119  pni::core::string link_target = get_link_target(link_node);
120 
121  //will throw type_error if the parent is not a group
122  GTYPE parent_group = as_group(parent);
123 
124  pni::io::nx::link(link_target,parent_group,link_name);
125  }
126 
127 
128 //end of namespace
129 }
130 }
131 }
132 }
auto link_target(const GTYPE< IMPID > &parent, const pni::core::string &lname) -> nxpath
get link target
Definition: nxlink.hpp:293
Definition: cbf_reader.hpp:41
auto link_name(const GTYPE< IMPID > &parent, size_t index) -> pni::core::string
get link name
Definition: nxlink.hpp:264
boost::property_tree::ptree node
alias for ptree
Definition: node.hpp:39
GTYPE as_group(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o)
as group wrapper
Definition: as_group.hpp:167
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
void link(const nxpath &target, const GTYPE< IMPID > &g, const pni::core::string &name)
create a link
Definition: nxlink.hpp:89