libalmemoryfastaccess  2.5.11.14a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  {
42  public:
45 
49  void StopAllAccess(void);
50 
56  void insertBuffer(const std::string &pName,
57  const ALValue &pBuff);
58 
67  void ConnectToVariables(const boost::shared_ptr<AL::ALBroker> pBroker,
68  const std::vector<std::string> &pListVariables,
69  bool bAllowNonExistantVariable = false);
70 
78  void ConnectToIntVariables(const boost::shared_ptr<AL::ALBroker> pBroker,
79  const std::vector<std::string> &pListVariables);
80 
87  static void *getDataPtr(boost::shared_ptr<AL::ALBroker> pBroker,
88  const std::string &pStrValue,
89  bool bAllowUnexistantVariable);
90 
97  template<typename T>
98  static T *getSafeDataPtr(boost::shared_ptr<ALMemoryProxy> pMemoryProxy,
99  const std::string &pStrValue,
100  T pValue)
101  {
102  bool insertData = false;
103 
104  try
105  {
106  insertData = !pMemoryProxy->getData(pStrValue).isValid();
107  }
108  catch(const std::exception &)
109  {
110  // If the data doesn't exist in memory getData return an invalid ALValue
111  // or throw. So in this case we try to insert data before getting pointer.
112  insertData = true;
113  }
114 
115  if(insertData)
116  {
117  pMemoryProxy->insertData(pStrValue, pValue);
118  }
119 
120  return static_cast<T*>(pMemoryProxy->getDataPtr(pStrValue));
121  }
122 
127  void GetValues(std::vector<float> &pListValue) const;
128 
133  void SetValues(const std::vector<float> &pListValue);
134 
139  void GetValues(std::vector<int> &pListValue) const;
140 
145  void SetValues(const std::vector<int> &pListValue);
146 
152  static bool InnerTest(const boost::shared_ptr<AL::ALBroker> pBroker);
153 
154  private:
159  static ALValue* getBuffer(const std::string &pName);
160 
162  boost::shared_ptr<AL::ALProxy> fMemoryProxy;
163 
165  std::vector<float *> fFloatPtrs;
167  std::vector<int *> fIntPtrs;
168 
170  bool fStopAllAccess;
171  };
172 
173 } // !namespace AL
174 #endif // _LIBALMEMORYFASTACCESS_ALMEMORYFASTACCESS_ALMEMORYFASTACCESS_H_
void insertBuffer(const std::string &pName, const ALValue &pBuff)
Insert a binary ALValue in ALMemory.
void StopAllAccess(void)
Remove all pointer.
void GetValues(std::vector< float > &pListValue) const
Get previous "connected" variables.
ALMemoryFastAccess is a fast access in Read/Write to some variables of ALMemory.
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.
static T * getSafeDataPtr(boost::shared_ptr< ALMemoryProxy > pMemoryProxy, const std::string &pStrValue, T pValue)
Get pointer on 32bit data.
void SetValues(const std::vector< float > &pListValue)
Set previous "connected" variables.
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.
static bool InnerTest(const boost::shared_ptr< AL::ALBroker > pBroker)
Test function.