BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::Path Class Reference

Supports navigation through SessionModel. More...

Public Types

using const_iterator = container_t::const_iterator
 
using container_t = std::vector< PathElement >
 
using iterator = container_t::iterator
 
using PathElement = int
 

Public Member Functions

 Path ()=default
 
void append (PathElement element)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
void prepend (PathElement element)
 
std::string str () const
 Returns string representing path ("0,0,1,3"). More...
 

Static Public Member Functions

static Path fromString (const std::string &str)
 Constructs Path object from string containing sequence of integers ("0,0,1,3"). More...
 
static Path fromVector (const std::vector< int > &data)
 Constructs Path object from vector of integers.. More...
 

Private Attributes

container_t m_data
 

Detailed Description

Supports navigation through SessionModel.

Contains a chain of indexes that have to be used to reach the desired SessionItem starting from the root item. Path class plays a role of simplified QModelIndex for SessionModel. Used for undo/redo only. Example of tree:

  • root path:""
    • child path:"0"
      • grandchild path:"0,0"
      • grandchild path:"0,1"
    • child path:"1"

Definition at line 35 of file path.h.

Member Typedef Documentation

◆ const_iterator

using ModelView::Path::const_iterator = container_t::const_iterator

Definition at line 40 of file path.h.

◆ container_t

Definition at line 38 of file path.h.

◆ iterator

using ModelView::Path::iterator = container_t::iterator

Definition at line 39 of file path.h.

◆ PathElement

Definition at line 37 of file path.h.

Constructor & Destructor Documentation

◆ Path()

ModelView::Path::Path ( )
default

Member Function Documentation

◆ append()

void Path::append ( Path::PathElement  element)

Definition at line 57 of file path.cpp.

58 {
59  m_data.push_back(element);
60 }
container_t m_data
Definition: path.h:60

References m_data.

Referenced by fromString(), and TEST_F().

◆ begin() [1/2]

Path::iterator Path::begin ( )

Definition at line 67 of file path.cpp.

68 {
69  return m_data.begin();
70 }

References m_data.

◆ begin() [2/2]

Path::const_iterator Path::begin ( ) const

Definition at line 72 of file path.cpp.

73 {
74  return m_data.begin();
75 }

References m_data.

◆ end() [1/2]

Path::iterator Path::end ( )

Definition at line 77 of file path.cpp.

78 {
79  return m_data.end();
80 }

References m_data.

◆ end() [2/2]

Path::const_iterator Path::end ( ) const

Definition at line 82 of file path.cpp.

83 {
84  return m_data.end();
85 }

References m_data.

◆ fromString()

Path Path::fromString ( const std::string &  str)
static

Constructs Path object from string containing sequence of integers ("0,0,1,3").

Definition at line 25 of file path.cpp.

26 {
27  Path result;
28 
29  std::string str_spaces(str);
30  std::replace(str_spaces.begin(), str_spaces.end(), ',', ' ');
31 
32  std::istringstream iss(str_spaces);
33  std::for_each(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
34  [&result](auto x) { result.append(std::stoi(x)); });
35  return result;
36 }
Supports navigation through SessionModel.
Definition: path.h:35
std::string str() const
Returns string representing path ("0,0,1,3").
Definition: path.cpp:49
void append(PathElement element)
Definition: path.cpp:57

References append(), and str().

Referenced by TEST_F().

Here is the call graph for this function:

◆ fromVector()

Path Path::fromVector ( const std::vector< int > &  data)
static

Constructs Path object from vector of integers..

Definition at line 40 of file path.cpp.

41 {
42  Path result;
43  std::for_each(data.begin(), data.end(), [&result](auto x) { result.append(x); });
44  return result;
45 }

Referenced by TEST_F().

◆ prepend()

void Path::prepend ( Path::PathElement  element)

Definition at line 62 of file path.cpp.

63 {
64  m_data.insert(m_data.begin(), element);
65 }

References m_data.

Referenced by ModelView::Utils::PathFromItem(), and TEST_F().

◆ str()

std::string Path::str ( ) const

Returns string representing path ("0,0,1,3").

Definition at line 49 of file path.cpp.

50 {
51  auto comma_fold = [](std::string a, int b) { return std::move(a) + ',' + std::to_string(b); };
52  return m_data.empty() ? std::string()
53  : std::accumulate(std::next(m_data.begin()), m_data.end(),
54  std::to_string(m_data[0]), comma_fold);
55 }
iterator end()
Definition: path.cpp:77
iterator begin()
Definition: path.cpp:67
Definition: filesystem.h:81

References m_data.

Referenced by fromString(), and TEST_F().

Member Data Documentation

◆ m_data

container_t ModelView::Path::m_data
private

Definition at line 60 of file path.h.

Referenced by append(), begin(), end(), prepend(), and str().


The documentation for this class was generated from the following files: