|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2011 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: stkpp::DManager 00027 * created on: 9 juin 2011 00028 * Purpose: Create an utility class in order to transfer the Data from 00029 * a DataFrame in an Array2D. 00030 * Author: iovleff, serge.iovleff@stkpp.org 00031 * 00032 **/ 00033 00038 #ifndef STK_EXPORTTOARRAY2D_H 00039 #define STK_EXPORTTOARRAY2D_H 00040 00041 #include "../../STKernel/include/STK_Array2D.h" 00042 00043 namespace STK 00044 { 00045 00049 template<class TYPE> 00050 class ExportToArray2D 00051 { 00052 public: 00056 ExportToArray2D( DataFrame const& df) 00057 : p_data_(0) 00058 { 00059 // create an empty Array2D 00060 p_data_ = new Array2D<TYPE>(); 00061 00062 // for each field Try a type conversion 00063 for(Integer iVar = df.firstCol(); iVar<=df.lastCol(); iVar++) 00064 { 00065 IVariable *const p_var = df.elt(iVar); 00066 // if there is a variable 00067 if (p_var) 00068 { 00069 // check the type of the variable 00070 if (p_var->getType() == IdTypeImpl<TYPE>::returnType()) 00071 { 00072 Variable<TYPE>* p_variable = static_cast<Variable<TYPE>* >(p_var); 00073 p_data_->pushBackCol(*p_variable); 00074 } 00075 } 00076 } 00077 } 00078 00080 virtual ~ExportToArray2D() 00081 { if (p_data_) delete p_data_;} 00082 00084 inline Array2D<TYPE>* const& array2D() const 00085 { return p_data_;} 00086 00088 inline void release() { p_data_ =0;} 00089 00090 private: 00092 Array2D<TYPE>* p_data_; 00093 }; 00094 00095 } 00096 00097 #endif /* STK_EXPORTTOARRAY2D_H */