HeapFactory.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef HEAP_FACTORY_H_
00004 #define HEAP_FACTORY_H_
00005 
00006 #include <fesa-core/DataStore/DeviceFactoryImp.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008 
00009 #include <cstring>
00010 
00011 namespace fesa
00012 {
00013 
00014 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType> class DeviceFactoryImp;
00015 
00024 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00025 class HeapFactory: public DeviceFactoryImp<GlobalDeviceType, DomainStoreType, DevInstType>
00026 {
00027   public:
00032     HeapFactory(const std::string& className);
00033 
00039     bool setUpMemory();
00040 };
00041 
00042 //******************************************************************
00043 
00044 //CRFESA-764 not all the methods have to be inline
00045 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00046 HeapFactory<GlobalDeviceType, DomainStoreType, DevInstType>::HeapFactory(const std::string& className) :
00047     DeviceFactoryImp<GlobalDeviceType, DomainStoreType, DevInstType> (className)
00048 {
00049 }
00050 
00051 template<typename GlobalDeviceType, typename DomainStoreType, typename DevInstType>
00052 bool HeapFactory<GlobalDeviceType, DomainStoreType, DevInstType>::setUpMemory()
00053 {
00054     char* p;
00055 
00056     //Calculates needed memory for all fields and all devices
00057     this->computeMemorySize();
00058     try
00059     {
00060         //Reserves memory for all fields and all devices
00061         p = new char[this->size_];
00062     }
00063     catch (std::bad_alloc& ex)
00064     {
00065         throw FesaException(__FILE__, __LINE__, FesaErrorAllocatingMemory.c_str(), ex.what());
00066     }
00067 
00068     //This sets the whole memory-block to zeros
00069     std::memset(p, 0, this->size_);
00070 
00071     //maps all fields (and devices) to the reserved memory-block
00072     this->mapFields(p, true);
00073     return true;
00074 }
00075 
00076 } // fesa
00077 
00078 #endif // HEAP_FACTORY_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1