libalmemoryfastaccess  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
almemoryfastaccess.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_
12 #define _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_
13 
14 #include <alvalue/alvalue.h>
15 #include <alproxies/almemoryproxy.h>
16 
17 #include <boost/shared_ptr.hpp>
18 
19 namespace AL
20 {
21  class ALProxy;
22  class ALBroker;
23 
41  {
46  typedef std::vector<float *> TVariablePtrArray;
51  typedef std::vector<float *> TFloatPtrArray;
56  typedef std::vector<int *> TIntPtrArray;
61  typedef TVariablePtrArray::iterator ITVariablePtrArray;
66  typedef TVariablePtrArray::const_iterator CITVariablePtrArray;
67 
68  public:
73 
78 
79 
83  void StopAllAccess(void);
84 
90  void insertBuffer(const std::string &pName,
91  const ALValue &pBuff);
92 
101  void ConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker,
102  const std::vector<std::string> &pListVariables,
103  bool bAllowNonExistantVariable = false);
104 
112  void ConnectToIntVariables(const boost::shared_ptr<AL::ALBroker> pBroker,
113  const std::vector<std::string> &pListVariables);
114 
121  static void *getDataPtr(boost::shared_ptr<AL::ALBroker> pBroker,
122  const std::string &pStrValue,
123  bool bAllowUnexistantVariable);
124 
131  template<typename T>
132  static T *getSafeDataPtr(boost::shared_ptr<ALMemoryProxy> pMemoryProxy,
133  const std::string &pStrValue,
134  T pValue)
135  {
136  bool insertData = false;
137 
138  try
139  {
140  insertData = !pMemoryProxy->getData(pStrValue).isValid();
141  }
142  catch(const std::exception &)
143  {
144  // If the data doesn't exist in memory getData return an invalid ALValue
145  // or throw. So in this case we try to insert data before getting pointer.
146  insertData = true;
147  }
148 
149  if(insertData)
150  {
151  pMemoryProxy->insertData(pStrValue, pValue);
152  }
153 
154  return static_cast<T*>(pMemoryProxy->getDataPtr(pStrValue));
155  }
156 
164  void directConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker,
165  const std::vector<std::string> &pListVariables,
166  bool bAllowUnexistantVariable = false);
167 
172  void GetValues(std::vector<float> &pListValue) const;
173 
178  void SetValues(const std::vector<float> &pListValue);
179 
184  void GetValues(std::vector<int> &pListValue) const;
185 
190  void SetValues(const std::vector<int> &pListValue);
191 
192 #ifdef DEBUG
193 
197  inline void DisableCheckOnNotExistingValueOrThings_Debug(void) { fbDisableCheking_Debug = true; };
198 #endif
199 
205  static bool InnerTest(const boost::shared_ptr<AL::ALBroker> pBroker);
206 
207  private:
212  static ALValue* getBuffer(const std::string &pName);
213 
215  boost::shared_ptr<AL::ALProxy> fMemoryProxy;
216 
218  bool fbIsLocal;
220  TVariablePtrArray fListVariablePtr;
222  TFloatPtrArray fListFloatPtr;
224  TIntPtrArray fListIntPtr;
225 
226 
228  ALValue fCommandToGetData;
230  ALValue fCommandToSetData;
231 
233  bool fStopAllAccess;
234 
235 #ifdef DEBUG
236 
237  bool fbDisableCheking_Debug;
238 #endif
239  };
240 
241 } // !namespace AL
242 #endif // _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_
ALMemoryFastAccess is a fast access in Read/Write to some variables of ALMemory.
ALMemoryFastAccess()
Default constructor.
void StopAllAccess(void)
Remove all pointer.
void GetValues(std::vector< float > &pListValue) const
Get previous "connected" variables.
~ALMemoryFastAccess()
Default destructor.
void directConnectToVariables(const boost::shared_ptr< AL::ALBroker > pBroker, const std::vector< std::string > &pListVariables, bool bAllowUnexistantVariable=false)
FIXME: No implementation.
static bool InnerTest(const boost::shared_ptr< AL::ALBroker > pBroker)
Test function.
void SetValues(const std::vector< float > &pListValue)
Set previous "connected" variables.
static T * getSafeDataPtr(boost::shared_ptr< ALMemoryProxy > pMemoryProxy, const std::string &pStrValue, T pValue)
Get pointer on 32bit data.
void ConnectToVariables(const boost::shared_ptr< AL::ALBroker > pBroker, const std::vector< std::string > &pListVariables, bool bAllowNonExistantVariable=false)
First time, you must "connect" to variables to access later, many times.
static void * getDataPtr(boost::shared_ptr< AL::ALBroker > pBroker, const std::string &pStrValue, bool bAllowUnexistantVariable)
Get pointer on 32bit data.
void ConnectToIntVariables(const boost::shared_ptr< AL::ALBroker > pBroker, const std::vector< std::string > &pListVariables)
First time, you must "connect" to int variables to access later, many times.
void insertBuffer(const std::string &pName, const ALValue &pBuff)
Insert a binary ALValue in ALMemory.