libalmemoryfastaccess
2.0.6.8
|
00001 00010 #pragma once 00011 #ifndef _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_ 00012 #define _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_ 00013 00014 #include <alvalue/alvalue.h> 00015 #include <alproxies/almemoryproxy.h> 00016 00017 #include <boost/shared_ptr.hpp> 00018 00019 namespace AL 00020 { 00021 class ALProxy; 00022 class ALBroker; 00023 00040 class ALMemoryFastAccess 00041 { 00046 typedef std::vector<float *> TVariablePtrArray; 00051 typedef std::vector<float *> TFloatPtrArray; 00056 typedef std::vector<int *> TIntPtrArray; 00061 typedef TVariablePtrArray::iterator ITVariablePtrArray; 00066 typedef TVariablePtrArray::const_iterator CITVariablePtrArray; 00067 00068 public: 00072 ALMemoryFastAccess(); 00073 00077 ~ALMemoryFastAccess(); 00078 00079 00083 void StopAllAccess(void); 00084 00090 void insertBuffer(const std::string &pName, 00091 const ALValue &pBuff); 00092 00101 void ConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker, 00102 const std::vector<std::string> &pListVariables, 00103 bool bAllowNonExistantVariable = false); 00104 00112 void ConnectToIntVariables(const boost::shared_ptr<AL::ALBroker> pBroker, 00113 const std::vector<std::string> &pListVariables); 00114 00121 static void *getDataPtr(boost::shared_ptr<AL::ALBroker> pBroker, 00122 const std::string &pStrValue, 00123 bool bAllowUnexistantVariable); 00124 00131 template<typename T> 00132 static T *getSafeDataPtr(boost::shared_ptr<ALMemoryProxy> pMemoryProxy, 00133 const std::string &pStrValue, 00134 T pValue) 00135 { 00136 bool insertData = false; 00137 00138 try 00139 { 00140 insertData = !pMemoryProxy->getData(pStrValue).isValid(); 00141 } 00142 catch(const std::exception &) 00143 { 00144 // If the data doesn't exist in memory getData return an invalid ALValue 00145 // or throw. So in this case we try to insert data before getting pointer. 00146 insertData = true; 00147 } 00148 00149 if(insertData) 00150 { 00151 pMemoryProxy->insertData(pStrValue, pValue); 00152 } 00153 00154 return static_cast<T*>(pMemoryProxy->getDataPtr(pStrValue)); 00155 } 00156 00164 void directConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker, 00165 const std::vector<std::string> &pListVariables, 00166 bool bAllowUnexistantVariable = false); 00167 00172 void GetValues(std::vector<float> &pListValue) const; 00173 00178 void SetValues(const std::vector<float> &pListValue); 00179 00184 void GetValues(std::vector<int> &pListValue) const; 00185 00190 void SetValues(const std::vector<int> &pListValue); 00191 00192 #ifdef DEBUG 00193 00197 inline void DisableCheckOnNotExistingValueOrThings_Debug(void) { fbDisableCheking_Debug = true; }; 00198 #endif 00199 00205 static bool InnerTest(const boost::shared_ptr<AL::ALBroker> pBroker); 00206 00207 private: 00212 static ALValue* getBuffer(const std::string &pName); 00213 00215 boost::shared_ptr<AL::ALProxy> fMemoryProxy; 00216 00218 bool fbIsLocal; 00220 TVariablePtrArray fListVariablePtr; 00222 TFloatPtrArray fListFloatPtr; 00224 TIntPtrArray fListIntPtr; 00225 00226 00228 ALValue fCommandToGetData; 00230 ALValue fCommandToSetData; 00231 00233 bool fStopAllAccess; 00234 00235 #ifdef DEBUG 00236 00237 bool fbDisableCheking_Debug; 00238 #endif 00239 }; 00240 00241 } // !namespace AL 00242 #endif // _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_