Context.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @file artis/context/Context.hpp
  3. * @author See the AUTHORS file
  4. */
  5. /*
  6. * Copyright (C) 2012-2019 ULCO http://www.univ-littoral.fr
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef __ARTIS_KERNEL_CONTEXT_HPP
  22. #define __ARTIS_KERNEL_CONTEXT_HPP
  23. #include <artis/context/State.hpp>
  24. #include <boost/serialization/serialization.hpp>
  25. namespace artis {
  26. namespace context {
  27. template<typename U>
  28. class Context {
  29. public:
  30. Context()
  31. :_begin(-1), _end(-1), _valid(false) { }
  32. Context(double begin, double end)
  33. :_begin(begin), _end(end), _valid(false) { }
  34. virtual ~Context() { }
  35. double begin() const { return _begin; }
  36. void begin(double begin) { _begin = begin; }
  37. double end() const { return _end; }
  38. void end(double end) { _end = end; }
  39. const Context& operator=(const Context& context)
  40. {
  41. _begin = context._begin;
  42. _end = context._end;
  43. _valid = context._valid;
  44. _state = context._state;
  45. return *this;
  46. }
  47. void saved() { _valid = true; }
  48. const State<U>& state() const { return _state; }
  49. State<U>& state() { return _state; }
  50. std::string to_string() const
  51. {
  52. return "begin: " + std::to_string(_begin) +
  53. "; end: " + std::to_string(_end) +
  54. "; valid: " + (_valid ? "true" : "false") +
  55. "; state: " + _state.to_string();
  56. }
  57. bool valid() const { return _valid; }
  58. private:
  59. friend class boost::serialization::access;
  60. template<class Archive>
  61. void serialize(Archive& ar, const unsigned int version)
  62. {
  63. (void) version;
  64. ar & _begin;
  65. ar & _end;
  66. ar & _state;
  67. ar & _valid;
  68. }
  69. double _begin;
  70. double _end;
  71. State<U> _state;
  72. bool _valid;
  73. };
  74. }
  75. }
  76. #endif