libalmemoryfastaccess
1.14.5
|
00001 00010 #pragma once 00011 #ifndef _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_ 00012 #define _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_ 00013 00014 # include <alvalue/alvalue.h> 00015 # include <alvalue/detail/alfunctorconvert.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 TVariablePtrArray::iterator ITVariablePtrArray; 00061 typedef TVariablePtrArray::const_iterator CITVariablePtrArray; 00062 00063 public: 00067 ALMemoryFastAccess(); 00068 00072 ~ALMemoryFastAccess(); 00073 00074 00078 static void StopAllAccess(void); 00079 00085 void insertBuffer(const std::string &pName, 00086 const ALValue &pBuff); 00087 00093 template <typename C> 00094 void insertObject(const std::string &pName, 00095 C pObject) 00096 { 00097 // serialize object and put binary data in ALValue because ALMemory only support ALValue 00098 AL::detail::converter<C> conv; 00099 ALValue bData = conv.convertToALValue(pObject); 00100 insertBuffer(pName, bData); 00101 } 00102 00108 template <typename C> 00109 static C getObject(const std::string &pName) 00110 { 00111 ALValue *val = getBuffer(pName); 00112 00113 // convert memory buffer to object 00114 AL::detail::converter<C> conv; 00115 C retObject = conv.convertFromALValue(*val); 00116 return retObject; 00117 } 00118 00127 void ConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker, 00128 const std::vector<std::string> &pListVariables, 00129 bool bAllowNonExistantVariable = false); 00130 00137 static void *getDataPtr(boost::shared_ptr<AL::ALBroker> pBroker, 00138 const std::string &pStrValue, 00139 bool bAllowUnexistantVariable); 00140 00148 void directConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker, 00149 const std::vector<std::string> &pListVariables, 00150 bool bAllowUnexistantVariable = false); 00151 00156 void GetValues(std::vector<float> &pListValue) const; 00157 00162 void SetValues(const std::vector<float> &pListValue); 00163 00164 #ifdef DEBUG 00165 00169 inline void DisableCheckOnNotExistingValueOrThings_Debug(void) { fbDisableCheking_Debug = true; }; 00170 #endif 00171 00177 static bool InnerTest(const boost::shared_ptr<AL::ALBroker> pBroker); 00178 00179 private: 00184 static ALValue* getBuffer(const std::string &pName); 00185 00187 boost::shared_ptr<AL::ALProxy> fMemoryProxy; 00188 00190 bool fbIsLocal; 00192 TVariablePtrArray fListVariablePtr; 00194 TFloatPtrArray fListFloatPtr; 00195 00196 00198 ALValue fCommandToGetData; 00200 ALValue fCommandToSetData; 00201 00202 #ifdef DEBUG 00203 00204 bool fbDisableCheking_Debug; 00205 #endif 00206 00208 static bool static_bStopAllAccess; 00209 }; 00210 00211 } // !namespace AL 00212 #endif // _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_