strusAnalyzer  0.17
position.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
11 #ifndef _STRUS_ANALYZER_POSITION_HPP_INCLUDED
12 #define _STRUS_ANALYZER_POSITION_HPP_INCLUDED
13 #include "strus/base/stdint.h"
14 
15 
17 namespace strus {
19 namespace analyzer {
20 
22 struct Position
23 {
24 public:
27  :m_seg(0),m_ofs(0){}
31  Position( int seg_, int ofs_)
32  :m_seg(seg_),m_ofs(ofs_){}
34 #if __cplusplus >= 201103L
35  Position( Position&& ) = default;
36  Position( const Position& ) = default;
37  Position& operator= ( Position&& ) = default;
38  Position& operator= ( const Position& ) = default;
39 #else
40  Position( const Position& o)
41  :m_seg(o.m_seg),m_ofs(o.m_ofs){}
42 #endif
43 
45  int seg() const {return m_seg;}
47  int ofs() const {return m_ofs;}
48 
50  void setSeg( int seg_)
51  {
52  m_seg = seg_;
53  }
55  void setOfs( int ofs_)
56  {
57  m_ofs = ofs_;
58  }
59 
61  int compare( const Position& o) const
62  {
63  return (m_seg == o.m_seg)
64  ? ((m_ofs < o.m_ofs) - (m_ofs > o.m_ofs))
65  : ((m_seg < o.m_seg) - (m_seg > o.m_seg));
66  }
67  bool operator <= (const Position& o) const
68  {
69  return (m_seg == o.m_seg)
70  ? (m_ofs <= o.m_ofs)
71  : (m_seg <= o.m_seg);
72  }
73  bool operator == (const Position& o) const
74  {
75  return (m_seg == o.m_seg && m_ofs == o.m_ofs);
76  }
77  bool operator < (const Position& o) const
78  {
79  return (m_seg == o.m_seg)
80  ? (m_ofs < o.m_ofs)
81  : (m_seg < o.m_seg);
82  }
83  bool operator > (const Position& o) const
84  {
85  return (m_seg == o.m_seg)
86  ? (m_ofs > o.m_ofs)
87  : (m_seg > o.m_seg);
88  }
89 
90 private:
91  uint32_t m_seg;
92  uint32_t m_ofs;
93 };
94 
95 }}//namespace
96 #endif
97 
Position()
Default constructor.
Definition: position.hpp:26
int seg() const
Get the position of the segment in the original source.
Definition: position.hpp:45
bool operator>(const Position &o) const
Definition: position.hpp:83
Position(int seg_, int ofs_)
Constructor.
Definition: position.hpp:31
Position(const Position &o)
Copy constructor.
Definition: position.hpp:40
bool operator==(const Position &o) const
Definition: position.hpp:73
int ofs() const
Get the byte position in the translated document segment (UTF-8)
Definition: position.hpp:47
int compare(const Position &o) const
Compare with another position.
Definition: position.hpp:61
void setOfs(int ofs_)
Set the byte offset in the segment.
Definition: position.hpp:55
bool operator<(const Position &o) const
Definition: position.hpp:77
void setSeg(int seg_)
Set the segment position.
Definition: position.hpp:50
Structure describing a position in a document source by segment and offset.
Definition: position.hpp:22
bool operator<=(const Position &o) const
Definition: position.hpp:67