PLearn 0.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions
PLearn::JulianizeVMatrix Class Reference

#include <JulianizeVMatrix.h>

Inheritance diagram for PLearn::JulianizeVMatrix:
Inheritance graph
[legend]
Collaboration diagram for PLearn::JulianizeVMatrix:
Collaboration graph
[legend]

List of all members.

Public Types

enum  DateCode { Date = 0, DateTime = 1 }
 This specifies the how the dates are coded in the source VMatrix; for now only two formats are allowed. More...

Public Member Functions

 JulianizeVMatrix (bool call_build_=false)
 Default constructor, the implementation in the .cc initializes all fields to reasonable default values.
 JulianizeVMatrix (VMat the_source, DateCode date_code=Date, int starting_column=0, bool call_build_=false)
 Simple constructor: takes as input only the date code and the starting column for a single date.
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual JulianizeVMatrixdeepCopy (CopiesMap &copies) const

Static Public Member Functions

static int dateCodeWidth (DateCode dc)
 Return the number of columns taken by each date code.
static string _classname_ ()
 Declares name and deepCopy methods.
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 Implement the base class abstract member function.
void setVMFields ()

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options. No options are currently supported.
static int newWidth (VMat the_source, DateCode dc)

Protected Attributes

vector< pair< int, DateCode > > cols_codes
 all columns/date codes
Vec source_row
 buffer for source row

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

JulianizeVMatrix

The purpose of a JulianizeVMatrix is to convert some columns of a source VMatrix into a JulianDayNumber (represented as a double). This VMatrix can convert any triplet of (YYYY,MM,DD) or sextuplet (YYY,MM,DD,HH,MM,SS) into a single double, whose integer part is the JDN and the fractional part codes the HH:MM:SS as a day fraction. Columns anywhere in the VMat can thereby be sepcified.

A class invariant here is that the member variable cols_codes (which stores pairs of the starting columns for dates to convert along with the date code for carrying out the conversion) is kept SORTED in order of increasing column.

Definition at line 68 of file JulianizeVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 70 of file JulianizeVMatrix.h.


Member Enumeration Documentation

This specifies the how the dates are coded in the source VMatrix; for now only two formats are allowed.

Enumerator:
Date 

(YYYY, MM, DD)

DateTime 

(YYYY, MM, DD, HH, MM, SS)

Definition at line 75 of file JulianizeVMatrix.h.

                  {
        Date = 0,                                
        DateTime = 1                             
    };

Constructor & Destructor Documentation

PLearn::JulianizeVMatrix::JulianizeVMatrix ( bool  call_build_ = false)

Default constructor, the implementation in the .cc initializes all fields to reasonable default values.

Definition at line 60 of file JulianizeVMatrix.cc.

References build_().

    : inherited(call_build_)
    /* all other compiler-supplied defaults are reasonable */
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::JulianizeVMatrix::JulianizeVMatrix ( VMat  the_source,
DateCode  date_code = Date,
int  starting_column = 0,
bool  call_build_ = false 
)

Simple constructor: takes as input only the date code and the starting column for a single date.

Starting columns are zero-based.

Definition at line 68 of file JulianizeVMatrix.cc.

References cols_codes, and setVMFields().

    : inherited(the_source,
                the_source->length(),
                newWidth(the_source, date_code),
                call_build_),
      cols_codes(1),
      source_row(the_source.width())
{
    cols_codes[0] = make_pair(starting_column, date_code);
    setVMFields();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::JulianizeVMatrix::_classname_ ( ) [static]

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

OptionList & PLearn::JulianizeVMatrix::_getOptionList_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

RemoteMethodMap & PLearn::JulianizeVMatrix::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

bool PLearn::JulianizeVMatrix::_isa_ ( const Object o) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

Object * PLearn::JulianizeVMatrix::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

StaticInitializer JulianizeVMatrix::_static_initializer_ & PLearn::JulianizeVMatrix::_static_initialize_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

void PLearn::JulianizeVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::SourceVMatrix.

Definition at line 150 of file JulianizeVMatrix.cc.

References PLearn::SourceVMatrix::build(), and build_().

Here is the call graph for this function:

void PLearn::JulianizeVMatrix::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 143 of file JulianizeVMatrix.cc.

References PLearn::SourceVMatrix::setMetaInfoFromSource().

Referenced by build(), and JulianizeVMatrix().

{
    // No options to build at this point
    setMetaInfoFromSource();
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::JulianizeVMatrix::classname ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

static int PLearn::JulianizeVMatrix::dateCodeWidth ( DateCode  dc) [inline, static]

Return the number of columns taken by each date code.

Definition at line 81 of file JulianizeVMatrix.h.

References PLERROR.

Referenced by setVMFields().

                                          {
        switch(dc) {
        case Date: return 3;
        case DateTime: return 6;
        }
        PLERROR("JulianizeVMatrix::dateCodeWidth: unknown date code");
        return 0;
    }

Here is the caller graph for this function:

void PLearn::JulianizeVMatrix::declareOptions ( OptionList ol) [static, protected]

Declares this class' options. No options are currently supported.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 126 of file JulianizeVMatrix.cc.

References PLearn::SourceVMatrix::declareOptions().

{
    // ### Declare all of this object's options here
    // ### For the "flags" of each option, you should typically specify
    // ### one of OptionBase::buildoption, OptionBase::learntoption or
    // ### OptionBase::tuningoption. Another possible flag to be combined with
    // ### is OptionBase::nosave

    // ### ex:
    // declareOption(ol, "myoption", &JulianizeVMatrix::myoption, OptionBase::buildoption,
    //               "Help text describing this option");
    // ...

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::JulianizeVMatrix::declaringFile ( ) [inline, static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 144 of file JulianizeVMatrix.h.

:
    // Return the new number of columns
JulianizeVMatrix * PLearn::JulianizeVMatrix::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

void PLearn::JulianizeVMatrix::getNewRow ( int  i,
const Vec v 
) const [protected, virtual]

Implement the base class abstract member function.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 84 of file JulianizeVMatrix.cc.

References PLearn::TVec< T >::begin(), cols_codes, std::copy(), Date, DateTime, PLearn::TVec< T >::end(), PLearn::SourceVMatrix::source, source_row, PLearn::PDateTime::toJulianDay(), and PLearn::PDate::toJulianDay().

{
    source->getRow(i, source_row);

    Vec::iterator
        src_beg = source_row.begin(),
        src_it  = source_row.begin(),
        src_end = source_row.end(),
        dst_it  = v.begin();
    vector< pair<int,DateCode> >::const_iterator
        codes_it  = cols_codes.begin(),
        codes_end = cols_codes.end();

    for ( ; codes_it < codes_end ; ++codes_it ) {
        // Copy what comes before the current date
        dst_it = copy(src_it, src_beg + codes_it->first, dst_it);
        src_it = src_beg + codes_it->first;

        // Now convert the date per se
        double converted_date = 0;
        int YYYY,MM,DD,hh,mm,ss;
        YYYY = int(*src_it++);
        MM   = int(*src_it++);
        DD   = int(*src_it++);
        switch(codes_it->second) {
        case Date:
            converted_date = PDate(YYYY,MM,DD).toJulianDay();
            break;
        case DateTime:
            hh = int(*src_it++);
            mm = int(*src_it++);
            ss = int(*src_it++);
            converted_date = PDateTime(YYYY,MM,DD,hh,mm,ss).toJulianDay();
            break;
        }
        *dst_it++ = converted_date;
    }

    // And now copy what comes after the last date
    copy(src_it, src_end, dst_it);
}

Here is the call graph for this function:

OptionList & PLearn::JulianizeVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

OptionMap & PLearn::JulianizeVMatrix::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

RemoteMethodMap & PLearn::JulianizeVMatrix::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file JulianizeVMatrix.cc.

void PLearn::JulianizeVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 156 of file JulianizeVMatrix.cc.

References PLearn::deepCopyField(), PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), and source_row.

{
    inherited::makeDeepCopyFromShallowCopy(copies);
    deepCopyField(source_row, copies);
    // cols_codes already deep-copied since it is an STL vector
}

Here is the call graph for this function:

static int PLearn::JulianizeVMatrix::newWidth ( VMat  the_source,
DateCode  dc 
) [inline, static, protected]

Definition at line 148 of file JulianizeVMatrix.h.

References PLearn::VMat::width().

                                                      {
        return the_source->width() - dateCodeWidth(dc) + 1;
    }

Here is the call graph for this function:

void PLearn::JulianizeVMatrix::setVMFields ( ) [protected]

Definition at line 163 of file JulianizeVMatrix.cc.

References cols_codes, Date, PLearn::VMField::Date, dateCodeWidth(), DateTime, PLearn::VMatrix::declareField(), PLearn::TVec< T >::size(), and PLearn::SourceVMatrix::source.

Referenced by JulianizeVMatrix().

{
    Array<VMField>& orig_fields = source->getFieldInfos();
    int new_field = 0;
    int cur_field = 0, end_field = orig_fields.size();
    vector< pair<int,DateCode> >::iterator it = cols_codes.begin(),
        end = cols_codes.end();

    for ( ; cur_field < end_field ; ++cur_field, ++new_field) {
        // We've got a date field
        if (it != end && it->first == cur_field) {
            switch(it->second) {
            case Date:
                this->declareField(new_field, "Date", VMField::Date);
                break;
            case DateTime:
                this->declareField(new_field, "DateTime", VMField::Date);
                break;
            }
            cur_field += dateCodeWidth(it->second)-1;
            ++it;
        }
        else {
            this->declareField(new_field, orig_fields[cur_field].name,
                               orig_fields[cur_field].fieldtype);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 144 of file JulianizeVMatrix.h.

vector< pair<int,DateCode> > PLearn::JulianizeVMatrix::cols_codes [protected]

all columns/date codes

Definition at line 92 of file JulianizeVMatrix.h.

Referenced by getNewRow(), JulianizeVMatrix(), and setVMFields().

buffer for source row

Definition at line 93 of file JulianizeVMatrix.h.

Referenced by getNewRow(), and makeDeepCopyFromShallowCopy().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines