PLearn 0.1
|
#include <ReadAndWriteCommand.h>
Public Member Functions | |
ReadAndWriteCommand () | |
virtual void | run (const vector< string > &args) |
The actual implementation of the 'ReadAndWriteCommand' command. | |
Static Protected Attributes | |
static PLearnCommandRegistry | reg_ |
This allows to register the 'ReadAndWriteCommand' command in the command registry. |
Definition at line 49 of file ReadAndWriteCommand.h.
PLearn::ReadAndWriteCommand::ReadAndWriteCommand | ( | ) |
Definition at line 53 of file ReadAndWriteCommand.cc.
: PLearnCommand("read_and_write", "Used to check (debug) the serialization system", "read_and_write <sourcefile> <destfile> [--update] [--mode={plearn_ascii,plearn_binary}] [modification string] ...\n" "Reads an Object (in PLearn serialization format) from the <sourcefile> and writes it to the <destfile>\n" "If the sourcefile ends with a .psave file, then it will not be subjected to macro preprosessing \n" "Otherwise (ex: .plearn .vmat) it will. \n" "If their is modification string in format option=value, the modification will be made to the object before saving\n" "The --update option makes that we generate the file only if we can calculate the modification time of the sourcefile and it is more recent than the destfile." ) {}
void PLearn::ReadAndWriteCommand::run | ( | const vector< string > & | args | ) | [virtual] |
The actual implementation of the 'ReadAndWriteCommand' command.
Implements PLearn::PLearnCommand.
Definition at line 68 of file ReadAndWriteCommand.cc.
References PLearn::endl(), PLearn::extract_extension(), i, PLearn::left(), PLearn::mtime(), PLearn::openFile(), PLCHECK, PLearn::PStream::plearn_ascii, PLearn::PStream::plearn_binary, PLERROR, PLearn::pout, PLearn::right(), PLearn::smartLoadObject(), and PLearn::split_on_first().
{ if(args.size()<2) PLERROR("read_and_write takes 2 or more arguments: <sourcefile> <destfile> [--update] [--mode={plearn_ascii,plearn_binary}][modification string] ..."); string source = args[0]; string dest = args[1]; string ext = extract_extension(source); PP<Object> o; time_t date_src=0; //read the file o=smartLoadObject(source, date_src); uint idx_start=2; PStream::mode_t mode = PStream::plearn_ascii; for(;idx_start<args.size();){ if(args[idx_start]=="--update"){ PLCHECK(date_src>0); time_t date_dst=mtime(dest); if((date_dst>date_src) && (date_src>0)){ pout << "The file is up to date. We don't regenerate it."<<endl; return; } } else if(args[idx_start]=="--mode=plearn_ascii"){ mode=PStream::plearn_ascii; } else if(args[idx_start]=="--mode=plearn_binary"){ mode=PStream::plearn_binary; } else break;//the rest are modification string idx_start++; } //modif the object string left; string right; for(uint i=idx_start; i<args.size();i++){ split_on_first(args[i], "=", left, right); o->setOption(left, right); } //write the file PStream out = openFile(dest, mode, "w"); if(!out) PLERROR("Could not open file %s for writing",dest.c_str()); out << *o; }
PLearnCommandRegistry PLearn::ReadAndWriteCommand::reg_ [static, protected] |
This allows to register the 'ReadAndWriteCommand' command in the command registry.
Definition at line 56 of file ReadAndWriteCommand.h.