|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // -------------------------------------------------------------------------- 00021 //-------------------------------------------------------------------------- 00022 #ifndef UNITRIGGER_H_ 00023 #define UNITRIGGER_H_ 00024 //-------------------------------------------------------------------------- 00025 namespace uniset 00026 { 00027 00029 class Trigger 00030 { 00031 public: 00032 Trigger(bool initial = false) noexcept 00033 { 00034 oldstate = initial; 00035 } 00036 00038 bool hi(bool state) noexcept 00039 { 00040 if (oldstate != state) 00041 { 00042 oldstate = state; 00043 00044 if (state) 00045 return true; 00046 } 00047 00048 return false; 00049 } 00051 bool low(bool state) noexcept 00052 { 00053 if (oldstate != state) 00054 { 00055 oldstate = state; 00056 00057 if (!state) 00058 return true; 00059 } 00060 00061 return false; 00062 } 00064 bool change(bool state) noexcept 00065 { 00066 if (oldstate != state) 00067 { 00068 oldstate = state; 00069 return true; 00070 } 00071 00072 return false; 00073 } 00074 00075 inline bool get() const noexcept 00076 { 00077 return oldstate; 00078 } 00079 00080 private: 00081 bool oldstate; 00082 }; 00083 // ------------------------------------------------------------------------- 00084 } // end of uniset namespace 00085 // -------------------------------------------------------------------------- 00086 #endif 00087 // --------------------------------------------------------------------------
1.7.6.1