Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

rmRefArray.h

Go to the documentation of this file.
00001 #ifndef __rmRefArray_h
00002 #define __rmRefArray_h
00003 
00004 #include "rmStatusArray.h"
00005 
00020 template<class T>
00021 class rmRefArray : public rmStatusArray<T>
00022 {
00023   public:
00024     rmRefArray(){}
00025     virtual ~rmRefArray(){}
00026 
00028     virtual int addElement(const T & aElement, unsigned long aID);
00030     virtual int modifyElement(unsigned long aID, const T & aElement);
00032     virtual int removeElement(unsigned long aID);
00033 
00035     virtual long addRef(unsigned long aID);
00037     virtual long release(unsigned long aID);
00038 };
00039 
00058 template<class T> int
00059 rmRefArray<T>::addElement(const T & aElement, unsigned long aID)
00060 {
00061   if (aID > mMaxId)
00062     return RMCLIENT_ERROR_BASE_ID;
00063 
00064   pair<map<unsigned long, T>::iterator, bool> ret;
00065   ret = mElementArray.insert(make_pair(aID, aElement));
00066 
00067   if(!ret.second)
00068     return RMCLIENT_ERROR_BASE_INSERT;
00069 
00070   ret.first->second.refCnt = 0;
00071 
00072   mMaxId++;
00073   if(mMaxId == 0)
00074     mMaxId++;
00075 
00076   return RMCLIENT_SUCCESS;
00077 }
00078 
00093 template<class T> int
00094 rmRefArray<T>::modifyElement(unsigned long aID, const T & aElement)
00095 {
00096   int ret;
00097   map<unsigned long, T>::iterator pos;
00098 
00099   ret = findId(aID, &pos);
00100   if(ret)
00101     return ret;
00102 
00103   if(pos->second.refCnt > 0)
00104     return RMCLIENT_ERROR_CC_REFCNT;
00105 
00106   pos->second = aElement;
00107   
00108   return RMCLIENT_SUCCESS;
00109 }
00110 
00123 template<class T> int
00124 rmRefArray<T>::removeElement(unsigned long aID)
00125 {
00126   int ret;
00127   map<unsigned long, T>::iterator pos;
00128 
00129   ret = findId(aID, &pos);
00130   if(ret)
00131     return ret;
00132 
00133   if(pos->second.refCnt > 0)
00134     return RMCLIENT_ERROR_CC_REFCNT;
00135 
00136   mElementArray.erase(pos);
00137   mPos = mElementArray.begin();
00138 
00139   return RMCLIENT_SUCCESS;
00140 }
00141 
00151 template<class T> long 
00152 rmRefArray<T>::addRef(unsigned long aID)
00153 {
00154   int ret;
00155   map<unsigned long, T>::iterator pos;
00156 
00157   ret = findId(aID, &pos);
00158   if(ret)
00159     return -1;
00160 
00161   if(pos->second.status != ACTIVE)
00162     return -1;
00163 
00164   return ++(pos->second.refCnt);
00165 }
00166 
00176 template<class T> long
00177 rmRefArray<T>::release(unsigned long aID)
00178 {
00179   int ret;
00180   map<unsigned long, T>::iterator pos;
00181 
00182   ret = findId(aID, &pos);
00183   if(ret)
00184     return -1;
00185 
00186   if(pos->second.status != ACTIVE)
00187     return -1;
00188 
00189   return --(pos->second.refCnt);
00190 }
00191 
00192 
00193 #endif //__rmRefArray_h

Generated on Tue Sep 10 16:46:33 2002 for ResourceMonitorSNMPSubagent by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002