Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

VirtualMatrixFactory.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Matrix_VirtualMatrixFactory_h
00002 #define Impala_Core_Matrix_VirtualMatrixFactory_h
00003 
00004 #include "Core/Matrix/VirtualMatrixIOBufferReader.h"
00005 #include "Core/Matrix/VirtualMatrixIOBufferWriter.h"
00006 #include "Core/Matrix/VirtualMatrixMemory.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Matrix
00013 {
00014 
00015 
00016 class VirtualMatrixFactory
00017 {
00018 public:
00019 
00020     static VirtualMatrixFactory&
00021     GetInstance()
00022     {
00023         static VirtualMatrixFactory theVirtualMatrixFactory;
00024         return theVirtualMatrixFactory;
00025     }
00026 
00027     VirtualMatrix*
00028     ConstructIOBufferReader(Persistency::File file)
00029     {
00030         Util::IOBuffer* buf = file.GetReadBuffer();
00031         if (!buf)
00032         {
00033             ILOG_ERROR("[ConstructIOBufferReader] Couldn't get readbufer");
00034             return 0;
00035         }
00036         Array::ArrayType at = Array::ReadRawArrayType(buf);
00037         buf->SetPosition(0);
00038         if (at == Array::ARRAY2DSCALARREAL32)
00039             return new VirtualMatrixIOBufferReader<Mat32>(buf, true);
00040         else
00041             return new VirtualMatrixIOBufferReader<Mat>(buf, true);
00042     }
00043 
00044     VirtualMatrix*
00045     ConstructIOBufferWriter(int nrRow, int nrCol, Persistency::File file,
00046                             bool write32, bool preWrite)
00047     {
00048         Util::IOBuffer* buf = file.GetWriteBuffer();
00049         if (!buf)
00050         {
00051             ILOG_ERROR("[ConstructIOBufferWriter] Couldn't get writebufer for"
00052                        << file.GetPath());
00053             return 0;
00054         }
00055         return new VirtualMatrixIOBufferWriter(nrRow, nrCol, buf, true, write32,
00056                                                preWrite);
00057     }
00058 
00059     VirtualMatrix*
00060     ConstructMemory(Persistency::File file, bool employ32)
00061     {
00062         Matrix::Mat* m = 0;
00063         Matrix::Mat32* m32 = 0;
00064         Array::ArrayType at = Array::ReadRawArrayType(file);
00065         if (at == Array::ARRAY2DSCALARREAL32)
00066         {
00067             Array::ReadRaw(m32, file);
00068         }
00069         else if (at == Array::ARRAY2DSCALARREAL64)
00070         {
00071             Array::ReadRaw(m, file);
00072         }
00073         else
00074         {
00075             ILOG_ERROR("[ConstructMemory] Couldn't read matrix");
00076             return 0;
00077         }
00078 
00079         if ((m == 0) && (m32 == 0))
00080         {
00081             ILOG_ERROR_NODE("[ConstructMemory] Couldn't read matrix");
00082             return 0;
00083         }
00084 
00085         if (employ32 && (m32 == 0))
00086         {
00087             Array::Set(m32, m);
00088             delete m;
00089             m = 0;
00090         }
00091 
00092         if (m)
00093             return ConstructMemory<Matrix::Mat>(m);
00094         else
00095             return ConstructMemory<Matrix::Mat32>(m32);
00096     }
00097 
00098     template <class ArrayT>
00099     VirtualMatrix*
00100     ConstructMemory(ArrayT* mat)
00101     {
00102         return new VirtualMatrixMemory<ArrayT>(mat);
00103     }
00104 
00105 private:
00106 
00107     VirtualMatrixFactory()
00108     {
00109     }
00110 
00111     ILOG_VAR_DEC;
00112 
00113 };
00114 
00115 ILOG_VAR_INIT(VirtualMatrixFactory, Impala.Core.Matrix);
00116 
00117 } // namespace Matrix
00118 } // namespace Core
00119 } // namespace Impala
00120 
00121 #endif

Generated on Thu Jan 13 09:04:34 2011 for ImpalaSrc by  doxygen 1.5.1