Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
light_wrapper.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 15.11.2013 02:40:53 CET
3 // File: light_wrapper.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __LIGHT_WRAPPER_HEADER
12 #define __LIGHT_WRAPPER_HEADER
13 
14 #include <Arduino.h>
15 #include "../ustd/shared_ptr.hpp"
16 
17 namespace tool{
18  namespace detail {
19  class light_wrapper_base_class {
20  public:
21  virtual ~light_wrapper_base_class() {}
22  //------------------- supported ops -------------------
23  virtual light_wrapper_base_class & operator=(state::light_enum const & in) = 0;
24  virtual void update() = 0;
25  private:
26 
27  };
28 
29  template<typename T>
30  class light_wrapper_derived_class: public light_wrapper_base_class {
31  public:
32  light_wrapper_derived_class(): val_() {
33  }
34  explicit light_wrapper_derived_class(T const & t): val_(t) {
35  }
36  //------------------- supported ops -------------------
37  light_wrapper_base_class & operator=(state::light_enum const & in) {
38  val_ = in;
39  return (*this);
40  }
41  void update() {
42  val_.update();
43  }
44  private:
45  T val_;
46  };
47  }//end namespace detail
48 
50  public:
51  light_wrapper_class(): ptr_() {
52  }
53  //------------------- supported ctors -------------------
54  template<typename pin_concept, bool on_state = HIGH>
55  light_wrapper_class(tool::light_class<pin_concept, on_state> const & t): ptr_(new detail::light_wrapper_derived_class<tool::light_class<pin_concept, on_state>>(t)) {
56  }
57  //------------------- supported operations -------------------
59  ASSERT(ptr_ != NULL)
60  ptr_->operator=(in);
61  return (*this);
62  }
63  void update() {
64  ASSERT(ptr_ != NULL)
65  ptr_->update();
66  }
67  private:
69  };
70 }//end namespace tool
71 
72 #endif //__LIGHT_WRAPPER_HEADER
light_enum
Definition: light.hpp:22
light_wrapper_class & operator=(state::light_enum const &in)
Definition: light_wrapper.hpp:58
light_wrapper_class()
Definition: light_wrapper.hpp:51
Definition: light_wrapper.hpp:49
void update()
Definition: light_wrapper.hpp:63
light_wrapper_class(tool::light_class< pin_concept, on_state > const &t)
Definition: light_wrapper.hpp:55
#define ASSERT(exp)
Definition: ard_assert.hpp:33
Definition: light.hpp:35