PLearn 0.1
JulianizeVMatrix.h
Go to the documentation of this file.
00001 
00002 // -*- C++ -*-
00003 
00004 // JulianizeVMatrix.h
00005 //
00006 // Copyright (C) 2003  Nicolas Chapados
00007 //
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are met:
00010 //
00011 //  1. Redistributions of source code must retain the above copyright
00012 //     notice, this list of conditions and the following disclaimer.
00013 //
00014 //  2. Redistributions in binary form must reproduce the above copyright
00015 //     notice, this list of conditions and the following disclaimer in the
00016 //     documentation and/or other materials provided with the distribution.
00017 //
00018 //  3. The name of the authors may not be used to endorse or promote
00019 //     products derived from this software without specific prior written
00020 //     permission.
00021 //
00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 //
00033 // This file is part of the PLearn library. For more information on the PLearn
00034 // library, go to the PLearn Web site at www.plearn.org
00035 
00036 /* *******************************************************
00037  * $Id: JulianizeVMatrix.h 8184 2007-10-15 20:09:46Z nouiz $
00038  ******************************************************* */
00039 
00041 #ifndef JulianizeVMatrix_INC
00042 #define JulianizeVMatrix_INC
00043 
00044 #include "SourceVMatrix.h"
00045 #include "VMat.h"
00046 
00047 #include <utility>
00048 #include <vector>
00049 #include <algorithm>
00050 
00051 namespace PLearn {
00052 using namespace std;
00053 
00068 class JulianizeVMatrix : public SourceVMatrix
00069 {
00070     typedef SourceVMatrix inherited;
00071 
00072 public:
00075     enum DateCode {
00076         Date = 0,                                
00077         DateTime = 1                             
00078     };
00079 
00081     static int dateCodeWidth(DateCode dc) {
00082         switch(dc) {
00083         case Date: return 3;
00084         case DateTime: return 6;
00085         }
00086         PLERROR("JulianizeVMatrix::dateCodeWidth: unknown date code");
00087         return 0;
00088     }
00089 
00090 protected:
00091 // DEPRECATED - use "source"    VMat underlying_;         //!< underlying vmat
00092     vector< pair<int,DateCode> > cols_codes;  
00093     mutable Vec source_row;                   
00094 
00095 public:
00096 
00097 
00098     // ************************
00099     // * public build options *
00100     // ************************
00101 
00102     // ### declare public option fields (such as build options) here
00103     // ...
00104 
00105     // ****************
00106     // * Constructors *
00107     // ****************
00108 
00111     JulianizeVMatrix(bool call_build_ = false);
00112 
00115     JulianizeVMatrix(VMat the_source,
00116                      DateCode date_code = Date,
00117                      int starting_column = 0,
00118                      bool call_build_ = false);
00119 
00120     // ******************
00121     // * Object methods *
00122     // ******************
00123 
00124 private:
00126     void build_();
00127 
00128 protected:
00130     static void declareOptions(OptionList& ol);
00131 
00133     virtual void getNewRow(int i, const Vec& v) const;
00134 
00135 public:
00136 
00137     // simply calls inherited::build() then build_()
00138     virtual void build();
00139 
00141     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00142 
00144     PLEARN_DECLARE_OBJECT(JulianizeVMatrix);
00145 
00146 protected:
00147     // Return the new number of columns
00148     static int newWidth(VMat the_source, DateCode dc) {
00149         return the_source->width() - dateCodeWidth(dc) + 1;
00150     }
00151 
00152     // Set the VMFields in this VMatrix from the source field names.  All
00153     // "date" fields are named "Date", and "date-time" are named "DateTime".
00154     void setVMFields();
00155 };
00156 
00157 DECLARE_OBJECT_PTR(JulianizeVMatrix);
00158 
00159 } // end of namespace PLearn
00160 #endif
00161 
00162 
00163 /*
00164   Local Variables:
00165   mode:c++
00166   c-basic-offset:4
00167   c-file-style:"stroustrup"
00168   c-file-offsets:((innamespace . 0)(inline-open . 0))
00169   indent-tabs-mode:nil
00170   fill-column:79
00171   End:
00172 */
00173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines