Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

OptionBase.h

Go to the documentation of this file.
00001 // -*- C++ -*-4 1999/10/29 20:41:34 dugas 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // Copyright (C) 2002 Frederic Morin 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 00038 /* ******************************************************* 00039 * $Id: OptionBase.h,v 1.8 2004/07/21 16:30:50 chrish42 Exp $ 00040 * This file is part of the PLearn library. 00041 ******************************************************* */ 00042 00043 00046 #ifndef OptionBase_INC 00047 #define OptionBase_INC 00048 00049 #include <plearn/io/pl_io.h> 00050 #include "PP.h" 00051 #include <plearn/io/PStream.h> 00052 #include <plearn/io/PStream_util.h> 00053 #include <vector> 00054 00055 namespace PLearn { 00056 using namespace std; 00057 00058 // Predeclaration of Object 00059 class Object; 00060 00062 class OptionBase: public PPointable 00063 { 00064 public: 00065 typedef unsigned int flag_t; // bit field 00066 00069 static const flag_t buildoption; 00070 00073 static const flag_t learntoption; 00074 00076 static const flag_t tuningoption; 00077 00079 static const flag_t nosave; 00080 00081 protected: 00082 string optionname_; // the name of the option 00083 flag_t flags_; 00084 string optiontype_; // the datatype of the option ("int" ...) 00085 string defaultval_; // string representation of the default value (will be printed by optionHelp()) 00086 string description_; // A description of this option 00087 00088 public: 00089 00092 OptionBase(const string& optionname, flag_t flags, 00093 const string& optiontype, const string& defaultval, 00094 const string& description) 00095 :optionname_(optionname), flags_(flags), 00096 optiontype_(optiontype), defaultval_(defaultval), 00097 description_(description) {} 00098 00099 virtual void read(Object* o, PStream& in) const = 0; 00100 00102 virtual bool shouldBeSkipped() const; 00103 00104 virtual void read_and_discard(PStream& in) const = 0; 00105 virtual void write(const Object* o, PStream& out) const = 0; 00106 00107 // writes the option into a string instead of a stream 00108 // (calls write on a string stream) 00109 string writeIntoString(const Object* o) const; 00110 00111 virtual Object* getAsObject(Object* o) const = 0; 00112 virtual const Object* getAsObject(const Object* o) const = 0; 00113 virtual Object *getIndexedObject(Object *o, int i) const = 0; 00114 virtual const Object *getIndexedObject(const Object *o, int i) const = 0; 00115 00117 virtual string optionHolderClassName(const Object* o) const = 0; 00118 00120 inline const string& optionname() const { return optionname_; } 00121 inline bool isOptionNamed(string name) const { return name == optionname(); } 00122 00123 inline const string& optiontype() const { return optiontype_; } 00124 inline const string& defaultval() const { return defaultval_; } 00125 inline const string& description() const { return description_; } 00126 inline flag_t flags() const { return flags_; } 00127 00129 inline void setDefaultVal(const string& newdefaultval) 00130 { defaultval_ = newdefaultval; } 00131 }; 00132 00133 typedef vector< PP<OptionBase> > OptionList; 00134 00135 00136 00137 } // end of namespace PLearn 00138 00139 #endif

Generated on Tue Aug 17 16:00:36 2004 for PLearn by doxygen 1.3.7