* switch from DeviceProxy -> AttributProxy
[diffractometer.git] / src / PogoHelper.h
blob33bfd2f8ae07f6a606d7ded07a82c3e5e8f5ed48
1 //+=============================================================================
2 //
3 // project : TANGO Utility
4 // file : PogoHelper.h:
5 // $Revision: 1.2 $
6 // $Author: piccaf $
7 //
8 // description : This utility class helps to allocate and desallocate READ attributes
9 // as POGO only generates pointers and let the Device developper manage memory allocation
11 // Note : these functions also initialise to a default value the allocated attributes
12 // Usage examples :
14 // CREATE_SCALAR_ATTRIBUTE(attr_hCoordinate_read); // by default initialised to 0
15 // CREATE_SCALAR_ATTRIBUTE(attr_hCoordinate_read,1); // initialised to 1
16 // DELETE_SCALAR_ATTRIBUTE(attr_hCoordinate_read)
18 // CREATE_DEVSTRING_ATTRIBUTE(attr_currentUMatrix_read,MAX_STRING_LENGTH);// by default initialised to ""
19 // CREATE_DEVSTRING_ATTRIBUTE(attr_currentUMatrix_read,MAX_STRING_LENGTH,"No U Matrix available");
20 // DELETE_DEVSTRING_ATTRIBUTE(attr_currentUMatrix_read)
22 // CREATE_SPECTRUM_ATTRIBUTE(attr_currentspectrum_read,MAX_LENGTH);// by default initialised to 0
23 // CREATE_SPECTRUM_ATTRIBUTE(attr_currentspectrum_read,MAX_LENGTH, 1);
24 // DELETE_SPECTRUM_ATTRIBUTE(attr_currentspectrum_read);
26 //-----------------------------------------------------------------------------
27 //
28 // function to delete a scalar attribut : You must pass the pointer to the attributs
29 // Usage : DELETE_SCALAR_ATTRIBUTE(attr_hCoordinate_read);
31 //-----------------------------------------------------------------------------
32 template <class _SCALAR> void DELETE_SCALAR_ATTRIBUTE(_SCALAR* attributeName)
35 if(attributeName)
37 delete attributeName;
38 attributeName = 0;
41 //=============================================================================
42 // function to allocate and initialise a read SCALAR attribute as generated by POGO
43 // Usage : ex : CREATE_SCALAR_ATTRIBUTE(attr_hCoordinate_read);
44 //=============================================================================
45 template <class _SCALAR> void CREATE_SCALAR_ATTRIBUTE(_SCALAR*& attributeName,_SCALAR default_value=0)
47 attributeName = new _SCALAR;
49 if(attributeName == 0)
51 TangoSys_OMemStream o;
52 o << "[" << __FILE__ << "::" << __LINE__ << "]" << std::ends;
53 Tango::Except::throw_exception (
54 (const char *)"OUT OF MEMORY",
55 (const char *)"out of memory error",
56 (const char *)(o.str().c_str()));
58 // then initialise scalar
59 (*attributeName) = (_SCALAR) default_value;
64 //=============================================================================
65 // function to allocate and initialise a DevString SCALAR attribute as generated by POGO
66 // Usage : ex : CREATE_DEVSTRING_ATTRIBUTE(attr_currentUMatrix_read,MAX_STRING_LENGTH,"No U Matrix available");
67 //=============================================================================
68 inline void CREATE_DEVSTRING_ATTRIBUTE(Tango::DevString*& attributeName, const int length, const char* init_string="")
70 attributeName = new char*;
72 if(attributeName == 0)
74 TangoSys_OMemStream o;
75 o << "[" << __FILE__ << "::" << __LINE__ << "]" << std::ends;
76 Tango::Except::throw_exception (
77 (const char *)"OUT OF MEMORY",
78 (const char *)"out of memory error",
79 (const char *)(o.str().c_str()));
82 //std::cout << length << std::endl;
83 (*attributeName) = new char[length];
84 if((*attributeName) == 0)
86 TangoSys_OMemStream o;
87 o << "[" << __FILE__ << "::" << __LINE__ << "]" << std::ends;
88 Tango::Except::throw_exception (
89 (const char *)"OUT OF MEMORY",
90 (const char *)"out of memory error",
91 (const char *)(o.str().c_str()));
93 ::strcpy(*attributeName, init_string);
96 //-----------------------------------------------------------------------------
97 //
98 // function to delete a DevString attribut : You must pass the pointer to the attributs
99 // Usage : DELETE_DEVSTRING_ATTRIBUTE(attr_currentUMatrix_read)
101 //-----------------------------------------------------------------------------
102 inline void DELETE_DEVSTRING_ATTRIBUTE(Tango::DevString* attributeName)
105 if(attributeName)
107 if(*attributeName)
108 delete [] (*attributeName);
109 delete attributeName;
110 attributeName = 0;
114 //=============================================================================
115 // function to allocate and initialise a read SPECTRUM attribute as generated by POGO
116 // Usage : ex : CREATE_SPECTRUM_ATTRIBUTE(attr_currentspectrum_read,MAX_LENGTH);
117 //=============================================================================
119 template <class _SPECTRUM> void CREATE_SPECTRUM_ATTRIBUTE(_SPECTRUM *& attributeName, const int size, _SPECTRUM default_value=0)
121 attributeName = new _SPECTRUM[size];
123 if(attributeName == 0)
125 TangoSys_OMemStream o;
126 o << "[" << __FILE__ << "::" << __LINE__ << "]" << std::ends;
127 Tango::Except::throw_exception (
128 (const char *)"OUT OF MEMORY",
129 (const char *)"out of memory error",
130 (const char *)(o.str().c_str()));
133 ::memset(attributeName, default_value, size * sizeof(_SPECTRUM));
136 //=============================================================================
137 // function to desallocate a read SPECTRUM attribute as generated by POGO
138 // Usage : ex : DELETE_SPECTRUM_ATTRIBUTE(attr_currentspectrum_read);
139 //=============================================================================
141 template <class _SPECTRUM> void DELETE_SPECTRUM_ATTRIBUTE(_SPECTRUM * attributeName )
143 if(attributeName)
145 delete [] (attributeName);