libpniio
get_path.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 18, 2013
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 #pragma once
23 
24 #include <pni/core/types.hpp>
25 #include "../nxobject.hpp"
26 #include "../nxobject_traits.hpp"
27 #include "get_class.hpp"
28 
29 namespace pni{
30 namespace io{
31 namespace nx{
32 
33 
55  template<
56  template<nximp_code> class OTYPE,
57  nximp_code IMPID
58  >
59  pni::core::string get_path(const OTYPE<IMPID> &o)
60  {
61  using object_type = typename nxobject_trait<IMPID>::object_type;
62 
63  return get_path(object_type(o));
64  }
65 
66  //------------------------------------------------------------------------
80  template<
81  typename GTYPE,
82  typename FTYPE,
83  typename ATYPE,
84  typename LTYPE
85  >
86  class get_path_visitor : public boost::static_visitor<pni::core::string>
87  {
88  private:
99  pni::core::string element_name(const pni::core::string &name,
100  const pni::core::string &type) const
101  {
102  pni::core::string ename(name);
103 
104  if((!type.empty()) && (type!="NXroot"))
105  ename += ":" + type;
106 
107  return ename;
108  }
109  public:
111  using result_type = pni::core::string;
113  using group_type = GTYPE;
115  using field_type = FTYPE;
117  using attribute_type = ATYPE;
119  using link_type = LTYPE;
120 
121  //-----------------------------------------------------------------
139  {
140  typedef nxobject<GTYPE,FTYPE,ATYPE,LTYPE> object_type;
141 
142  //determine the name and the type of the group
143  pni::core::string group_name = g.name();
144  pni::core::string group_type = get_class(object_type(g));
145 
146  //assemble the element name
147  pni::core::string ename = element_name(group_name,group_type);
148 
149  //the recursion is done when we arrived at the root group
150  if((group_type == "NXroot") || (group_name == "/"))
151  return ename;
152  else
153  return get_path(g.parent()) + "/" + ename;
154 
155  }
156 
157  //-----------------------------------------------------------------
176  {
177  return get_path(f.parent())+"/"+f.name();
178  }
179 
180  //-----------------------------------------------------------------
199  {
200  return get_path(a.parent())+"@"+a.name();
201  }
202 
204  {
205  return get_path(l.parent())+"/"+l.name();
206  }
207  };
208 
232  template<
233  typename GTYPE,
234  typename FTYPE,
235  typename ATYPE,
236  typename LTYPE
237  >
238  pni::core::string get_path(const nxobject<GTYPE,FTYPE,ATYPE,LTYPE> &o)
239  {
240  pni::core::string path = boost::apply_visitor(get_path_visitor<GTYPE,FTYPE,ATYPE,LTYPE>(),o);
241 
242  //repair two leading // which can happen in some cases
243  if((path.size()>=2) &&
244  (path[0]=='/') &&
245  (path[1]=='/'))
246  {
247  return pni::core::string(path,1,path.size()-1);
248  }
249  else
250  return path;
251  }
252 
253 //end of namespace
254 }
255 }
256 }
pni::core::string result_type
result type
Definition: get_path.hpp:111
pni::core::string element_name(const pni::core::string &name, const pni::core::string &type) const
assembles the group element name
Definition: get_path.hpp:99
result_type operator()(const attribute_type &a) const
process attribute instances
Definition: get_path.hpp:198
GTYPE group_type
Nexus group type.
Definition: get_path.hpp:113
nexus object traits
Definition: nxobject_traits.hpp:44
get path visitor
Definition: get_path.hpp:86
result_type operator()(const link_type &l) const
Definition: get_path.hpp:203
Definition: cbf_reader.hpp:41
ATYPE attribute_type
Nexus attribute type.
Definition: get_path.hpp:117
FTYPE field_type
Nexus field type.
Definition: get_path.hpp:115
nximp_code
implementation codes
Definition: nximp_code.hpp:40
pni::core::string get_class(const OTYPE< IMPID > &group)
get the class of a group
Definition: get_class.hpp:56
LTYPE link_type
NeXus link type.
Definition: get_path.hpp:119
result_type operator()(const field_type &f) const
process field instances
Definition: get_path.hpp:175
pni::core::string get_path(const OTYPE< IMPID > &o)
get object path
Definition: get_path.hpp:59
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
result_type operator()(const group_type &g) const
process group instances
Definition: get_path.hpp:138