PLearn 0.1
PTest.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PTest.cc
00004 //
00005 // Copyright (C) 2005 Olivier Delalleau 
00006 // 
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 // 
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 // 
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 // 
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 // 
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 /* *******************************************************      
00036    * $Id: .pyskeleton_header 544 2003-09-01 00:05:31Z plearner $ 
00037    ******************************************************* */
00038 
00039 // Authors: Olivier Delalleau
00040 
00044 #include "PTest.h"
00045 #include <plearn/io/fileutils.h>        
00046 #include <plearn/io/load_and_save.h>    
00047 
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00052 PLEARN_IMPLEMENT_OBJECT(
00053     PTest,
00054     "Base class for PLearn internal tests.",
00055     ""
00056 );
00057 
00059 // PTest //
00061 PTest::PTest():
00062     save(true)
00063 {}
00064 
00066 // build //
00068 void PTest::build()
00069 {
00070     inherited::build();
00071     build_();
00072 }
00073 
00075 // makeDeepCopyFromShallowCopy //
00077 void PTest::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00078 {
00079     inherited::makeDeepCopyFromShallowCopy(copies);
00080 
00081     // ### Call deepCopyField on all "pointer-like" fields 
00082     // ### that you wish to be deepCopied rather than 
00083     // ### shallow-copied.
00084     // ### ex:
00085     // deepCopyField(trainvec, copies);
00086 
00087     // ### Remove this line when you have fully implemented this method.
00088     PLERROR("PTest::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00089 }
00090 
00092 // declareOptions //
00094 void PTest::declareOptions(OptionList& ol)
00095 {
00096     // Option 'name' is declared as 'nosave' because most PTest subclasses will
00097     // either use the default name (= classname()), or set their own name,
00098     // without needing to have the user set it by himself.
00099     // However, a subclass may redeclare this option as a 'buildoption' if
00100     // needed.
00101     declareOption(ol, "name", &PTest::name, OptionBase::nosave,
00102         "The name of this test. If left empty, it will be set to classname()\n"
00103         "at build time.");
00104 
00105     declareOption(ol, "save", &PTest::save, OptionBase::buildoption,
00106         "If set to 1, this object will be saved to 'save_path'.");
00107 
00108     declareOption(ol, "save_path", &PTest::save_path, OptionBase::buildoption,
00109         "The file where this test object should be saved (if empty, it will\n"
00110         "be set to 'name'.psave).");
00111 
00112     // Now call the parent class' declareOptions
00113     inherited::declareOptions(ol);
00114 }
00115 
00117 // build_ //
00119 void PTest::build_()
00120 {
00121     if (name.empty())
00122         name = this->classname();
00123 }
00124 
00126 // run //
00128 void PTest::run()
00129 {
00130     this->perform();
00131     if (save) {
00132         PPath file = save_path.isEmpty() ? PPath(name + ".psave") : save_path;
00133         if (pathexists(file))
00134             PLERROR("In PTest::run - File '%s' already exists",
00135                     file.errorDisplay().c_str());
00136         PP<PTest> test_to_save = this;
00137         PLearn::save(file, test_to_save);
00138     }
00139 }
00140 
00141 } // end of namespace PLearn
00142 
00143 
00144 /*
00145   Local Variables:
00146   mode:c++
00147   c-basic-offset:4
00148   c-file-style:"stroustrup"
00149   c-file-offsets:((innamespace . 0)(inline-open . 0))
00150   indent-tabs-mode:nil
00151   fill-column:79
00152   End:
00153 */
00154 // 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