libpniio
nxpath/nxpath.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 //
20 // Created on: Feb 11, 2013
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 #pragma once
24 
25 #include <utility>
26 #include <pni/core/types.hpp>
27 #include <list>
28 
29 namespace pni{
30 namespace io{
31 namespace nx{
32 
60  class nxpath
61  {
62  public:
64  typedef std::pair<pni::core::string,pni::core::string> element_type;
66  typedef std::list<element_type> elements_type;
68  typedef elements_type::iterator iterator;
70  typedef elements_type::const_iterator const_iterator;
71 
72  private:
74  pni::core::string _file_name;
76  pni::core::string _attribute_name;
78  elements_type _elements;
79 
80  public:
81  //===============constructors and destructor=======================
85  nxpath();
86  //-----------------------------------------------------------------
94  explicit nxpath(const pni::core::string &file,
95  const elements_type &groups,
96  const pni::core::string &attr);
97 
98  //-----------------------------------------------------------------
110  static nxpath from_string(const pni::core::string &input);
111 
112  //-----------------------------------------------------------------
121  static pni::core::string to_string(const nxpath &p);
122 
123  //===============public member methods=============================
130  bool has_filename() const noexcept;
131 
132  //-----------------------------------------------------------------
139  bool has_attribute() const noexcept;
140 
141  //-----------------------------------------------------------------
145  pni::core::string filename() const noexcept;
146 
147  //----------------------------------------------------------------
151  void filename(const pni::core::string &f);
152 
153  //-----------------------------------------------------------------
157  pni::core::string attribute() const noexcept;
158 
159  //----------------------------------------------------------------
163  void attribute(const pni::core::string &a);
164 
165  //-----------------------------------------------------------------
176  void push_back(const element_type &o);
177 
178  //----------------------------------------------------------------
186  void push_front(const element_type &o);
187 
188  //----------------------------------------------------------------
192  void pop_front();
193 
194  //----------------------------------------------------------------
198  void pop_back();
199 
200  //-----------------------------------------------------------------
207  element_type front() const
208  {
209  return _elements.front();
210  }
211 
212  //----------------------------------------------------------------
220  element_type back() const;
221 
222  //------------------------------------------------------------------
226  size_t size() const;
227 
228  //===================iterators======================================
232  iterator begin();
233 
234  //----------------------------------------------------------------
237  iterator end();
238 
239  //----------------------------------------------------------------
243  const_iterator begin() const;
244 
245  //----------------------------------------------------------------
249  const_iterator end() const;
250  };
251 
252 
253 //end of namespace
254 }
255 }
256 }
iterator begin()
get iterator to first element
Definition: nxpath.cpp:144
static nxpath from_string(const pni::core::string &input)
create path from string
Definition: nxpath.cpp:52
elements_type::iterator iterator
iterator over elements
Definition: nxpath/nxpath.hpp:68
pni::core::string _file_name
name of the file
Definition: nxpath/nxpath.hpp:74
void pop_front()
last element from path
Definition: nxpath.cpp:120
void push_front(const element_type &o)
prepend element
Definition: nxpath.cpp:114
std::list< element_type > elements_type
a list of subsequent objects
Definition: nxpath/nxpath.hpp:66
elements_type::const_iterator const_iterator
const iterator over elements
Definition: nxpath/nxpath.hpp:70
element_type front() const
get last element
Definition: nxpath/nxpath.hpp:207
iterator end()
get iterator to last+1 element
Definition: nxpath.cpp:150
size_t size() const
return number of group entries
Definition: nxpath.cpp:138
pni::core::string filename() const noexcept
return the filename
Definition: nxpath.cpp:79
static pni::core::string to_string(const nxpath &p)
create string from path
Definition: nxpath.cpp:58
void pop_back()
remove first element from path
Definition: nxpath.cpp:126
Definition: cbf_reader.hpp:41
std::pair< pni::core::string, pni::core::string > element_type
object element (groupname:class)
Definition: nxpath/nxpath.hpp:64
bool has_attribute() const noexcept
true if has attribute
Definition: nxpath.cpp:73
void push_back(const element_type &o)
append element
Definition: nxpath.cpp:103
Nexus path class.
Definition: nxpath/nxpath.hpp:60
elements_type _elements
list of groups
Definition: nxpath/nxpath.hpp:78
element_type back() const
get first element
Definition: nxpath.cpp:132
pni::core::string attribute() const noexcept
return the attribute name
Definition: nxpath.cpp:91
bool has_filename() const noexcept
true if has filename
Definition: nxpath.cpp:67
nxpath()
default constructor
Definition: nxpath.cpp:36
pni::core::string _attribute_name
name of an attribute
Definition: nxpath/nxpath.hpp:76