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

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <ExtractOptionCommand.h>

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

List of all members.

Public Member Functions

 ExtractOptionCommand ()
virtual void run (const std::vector< std::string > &args)
 The actual implementation of the 'ExtractOptionCommand' command.

Static Protected Attributes

static PLearnCommandRegistry reg_
 This allows to register the 'ExtractOptionCommand' command in the command registry.

Private Types

typedef PLearnCommand inherited

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 58 of file ExtractOptionCommand.h.


Member Typedef Documentation

Definition at line 60 of file ExtractOptionCommand.h.


Constructor & Destructor Documentation

PLearn::ExtractOptionCommand::ExtractOptionCommand ( )

Definition at line 52 of file ExtractOptionCommand.cc.

    : PLearnCommand(
        "extract_option",
        "Extracts an option from a saved plearn object (.psave) and saves it to its own file.",
        "   extract_option <objfile.psave> <optionname> <optionfile.psave>\n"
        "OR extract_option <objfile.psave> <optionname> <optionfile.pmat> <transpose> \n"
        "The first form will output the option serialized in plearn_ascii format\n"
        "The second form is available only for Mat or Vec options, and will save it as a .pmat file.\n"
        "For Mat, if transpose is 0 then the matrix won't be transposed. If it's 1 it will be transposed.\n"
        "For Vec, if transpose is 0 then it will be saved as a row matrix. If it's 1, i will be saved as a column matrix.\n"
        )
{}

Member Function Documentation

void PLearn::ExtractOptionCommand::run ( const std::vector< std::string > &  args) [virtual]

The actual implementation of the 'ExtractOptionCommand' command.

Implements PLearn::PLearnCommand.

Definition at line 66 of file ExtractOptionCommand.cc.

References PLearn::endl(), in, PLearn::TMat< T >::length(), PLearn::loadObject(), m, PLearn::openFile(), PLearn::openString(), PLearn::perr, PLearn::PStream::plearn_ascii, PLERROR, PLearn::VMatrix::putMat(), PLearn::toint(), PLearn::transpose(), and PLearn::TMat< T >::width().

{
    if(args.size()==3)
    {
        string objfile = args[0];
        string optionname = args[1];
        string optionfile = args[2];
        PP<Object> obj = loadObject(objfile);
        PStream out = openFile(optionfile, PStream::plearn_ascii, "w");
        obj->writeOptionVal(out, optionname);
        out = 0;
        perr << "Option " << optionname << " has been written to file " << optionfile << endl;
    }
    else if(args.size()==4)
    {
        string objfile = args[0];
        string optionname = args[1];
        string optionfile = args[2];
        int do_transpose = toint(args[3]);
        PP<Object> obj = loadObject(objfile);
        string optionval = obj->getOption(optionname);
        bool ismat = false;
        Mat m;
        try
        {
            PStream in = openString(optionval, PStream::plearn_ascii);
            in >> m;
            perr << "Extracted a " << m.length() << " x " << m.width() << " matrix" << endl;
            ismat = true;
        }
        catch(const PLearnError& e)
        { ismat = false; }

        if(!ismat)
        {
            Vec v;
            PStream in = openString(optionval, PStream::plearn_ascii);
            in >> v;
            perr << "Extracted a vector of length " << v.length() << endl;
            m = v.toMat(1,v.length());
        }

        if(do_transpose==1)
            m = transpose(m);
        FileVMatrix vmat(optionfile, m.length(), m.width());
        vmat.putMat(0, 0, m);
        vmat.flush();
        perr << "Option " << optionname << " has been written to file " << optionfile << endl;
    }
    else
        PLERROR("Wrong number of argumens, please consult help");    
}

Here is the call graph for this function:


Member Data Documentation

This allows to register the 'ExtractOptionCommand' command in the command registry.

Definition at line 67 of file ExtractOptionCommand.h.


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