• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

AP_Var.h

Go to the documentation of this file.
00001 // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
00002 //
00003 // This is free software; you can redistribute it and/or modify it under
00004 // the terms of the GNU Lesser General Public License as published by the
00005 // Free Software Foundation; either version 2.1 of the License, or (at
00006 // your option) any later version.
00007 //
00011 #ifndef AP_Var_H
00012 #define AP_Var_H
00013 
00014 class AP_VarI
00015 {
00016 public:
00017 
00019         virtual void setF(const float & val) = 0;
00020 
00022         virtual const float getF() = 0;
00023 
00025         virtual void setI(const int16_t & val) = 0;
00026 
00028         virtual const int16_t getI() = 0;
00029 
00031         virtual void setB(const bool & val) = 0;
00032 
00034         virtual const bool getB() = 0;
00035 
00037         virtual void save() = 0;
00038 
00040         virtual void load() = 0;
00041 
00043         virtual const char * getName() = 0;
00044 
00047         virtual const bool & getSync() = 0;
00048 
00050         virtual void setSync(const bool & sync) = 0;
00051 };
00052 
00056 template  <class type>
00057 class AP_Var : public AP_VarI
00058 {
00059 public:
00061         AP_Var(const type & data, const char * name = "", const char * parentName = "", const bool & sync=false) :
00062                 _data(data), _name(name), _parentName(parentName), _sync(sync)
00063         {
00064         }
00065 
00067         AP_Var(AP_VarI & v)
00068         {
00069                 setF(v.getF()); 
00070         }
00071 
00073         void set(const type & val) {
00074                 _data = val;
00075                 if (_sync) save();
00076         }
00077 
00079         const type & get() {
00080                 if (_sync) load();
00081                 return _data;
00082         }
00083 
00085         virtual void setF(const float & val) {
00086                 set(val);
00087         }
00088 
00090         virtual const float getF() {
00091                 return get();
00092         }
00093 
00095         virtual void setI(const int16_t & val) {
00096                 set(val);
00097         }
00098 
00100         virtual const int16_t getI() {
00101                 return get();
00102         }
00103 
00105         virtual void setB(const bool & val) {
00106                 set(val);
00107         }
00108 
00110         virtual const bool getB() {
00111                 return get();
00112         }
00113 
00115         virtual void save()
00116         {
00117         }
00118 
00120         virtual void load()
00121         {
00122         }
00123 
00125         virtual const char * getName() { return _name; }
00126 
00128         virtual const char * getParentName() { return _parentName; }
00129 
00132         virtual const bool & getSync() { return _sync; }
00133         virtual void setSync(const bool & sync) { _sync = sync; }
00134 
00135 protected:
00136         type _data; 
00137         const char * _name; 
00138         const char * _parentName; 
00139         bool _sync; 
00140 };
00141 
00142 typedef AP_Var<float> AP_Float;
00143 typedef AP_Var<int8_t> AP_Int8;
00144 typedef AP_Var<uint8_t> AP_Uint8;
00145 typedef AP_Var<int16_t> AP_Int16;
00146 typedef AP_Var<uint16_t> AP_Uint16;
00147 typedef AP_Var<int32_t> AP_Int32;
00148 typedef AP_Var<uint32_t> AP_Unt32;
00149 typedef AP_Var<bool> AP_Bool;
00150 
00151 #endif // AP_Var_H

Generated for ArduPilot Libraries by doxygen