SequenceNumber.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
28 //----------------------------------------------------------------------
29 #ifndef ICL_CORE_SEQUENCE_NUMBER_H_INCLUDED
30 #define ICL_CORE_SEQUENCE_NUMBER_H_INCLUDED
31 
32 #include "icl_core/BaseTypes.h"
33 
34 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
35 # include "icl_core/Deprecate.h"
36 #endif
37 
38 namespace icl_core {
39 
44 template <typename TBase, TBase max_value, TBase min_value = 0, TBase initial_value = min_value>
46 {
47 public:
52  explicit SequenceNumber(TBase value = initial_value)
53  : m_value(value)
54  {
55  }
56 
61  : m_value(other.m_value)
62  {
63  }
64 
69  {
70  m_value = other.m_value;
71  return *this;
72  }
73 
78  {
79  m_value = value;
80  return *this;
81  }
82 
86  bool operator < (const SequenceNumber& other) const
87  {
88  if (m_value < other.m_value)
89  {
90  return (other.m_value - m_value) < max_value / 2;
91  }
92  else
93  {
94  return (m_value - other.m_value) > max_value / 2;
95  }
96  }
97 
101  bool operator <= (const SequenceNumber& other) const
102  {
103  return (*this) < other || (*this) == other;
104  }
105 
109  bool operator > (const SequenceNumber& other) const
110  {
111  return (*this) != other && !((*this) < other);
112  }
113 
117  bool operator >= (const SequenceNumber& other) const
118  {
119  return !((*this) < other);
120  }
121 
125  bool operator == (const SequenceNumber& other) const
126  {
127  return m_value == other.m_value;
128  }
129 
133  bool operator != (const SequenceNumber& other) const
134  {
135  return !((*this) == other);
136  }
137 
142  {
143  ++m_value;
144  if (m_value >= max_value)
145  {
146  m_value = min_value;
147  }
148  return *this;
149  }
150 
155  {
156  SequenceNumber result = *this;
157  ++(*this);
158  return result;
159  }
160 
164  operator TBase () const
165  {
166  return m_value;
167  }
168 
172  static TBase maxValue()
173  {
174  return max_value;
175  }
176 
180  static TBase minValue()
181  {
182  return min_value;
183  }
184 
186 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
187 
193 
199 
200 #endif
201 
203 private:
204  TBase m_value;
205 };
206 
207 }
208 
209 #endif
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
SequenceNumber & operator++()
bool operator<=(const SequenceNumber &other) const
Contains macros to deprecate classes, types, functions and variables.
bool operator>=(const SequenceNumber &other) const
bool operator<(const SequenceNumber &other) const
SequenceNumber(const SequenceNumber &other)
bool operator==(const SequenceNumber &other) const
bool operator!=(const SequenceNumber &other) const
SequenceNumber & operator=(const SequenceNumber &other)
SequenceNumber(TBase value=initial_value)
Contains Interface base classes and base types.
bool operator>(const SequenceNumber &other) const
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58