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

ImageProcessorDescription.hpp

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00019 #ifndef _ImageProcessorDescription_hpp
00020 #define _ImageProcessorDescription_hpp
00021 
00022 #include<ImLib3D/ImageProcessorsDescription.hpp>
00023 #include<algorithm>
00024 
00026 
00027 class ImProcStringArgument : public XIPD::Argument
00028 {
00029 protected:
00031     ImageProcessorsDescription &improcs;
00033     XIPD::ArgumentType *typeDesc;
00034 //  bool ignoreOutput;
00035 public:
00036     string Name(){return name;}
00037     string Type(){return type;}
00038     XIPD::ArgumentType *TypeDescritption(){return typeDesc;}
00039     bool IsInput(){return direction!="output";}
00040     bool IsOptional(){return isOptional=="true";}
00041     string OptType(){return optType;}
00042     string Default(){return defaultValue;}
00043     string FullSwitch()
00044     {
00045         string res="--";
00046         for(uint i=0;i<name.size();i++)
00047         {
00048             res+=isspace(name[i]) ? '-' : tolower(name[i]);
00049         }
00050         return res;
00051     }
00053 
00054     virtual bool IsValid(const string &strArg,string &message)
00055     {
00056         return true;//unkown arg types are ok by default
00057     }
00058     
00059     virtual ~ImProcStringArgument(){;}
00061     static ImProcStringArgument *Create(XIPD::Argument &argument,ImageProcessorsDescription &improcs);
00062     ImProcStringArgument(XIPD::Argument &parent,ImageProcessorsDescription &_improcs):
00063         XIPD::Argument(parent),improcs(_improcs)
00064     {
00065         typeDesc=improcs.GetArgumentType(Type(),false);
00066     }
00067 };
00068 
00070 class ImageArgument  : public ImProcStringArgument
00071 {
00072 public:
00073     virtual bool IsValid(const string &strArg,string &message);
00075     ImageArgument(XIPD::Argument &parent,ImageProcessorsDescription &_improcs):
00076         ImProcStringArgument(parent,_improcs)
00077     {}
00078 };
00079 
00081 class ListArgument  : public ImProcStringArgument
00082 {
00083     virtual bool IsValid(const string &strArg,string &message)
00084     {
00085         if(find(Items().begin(),Items().end(),strArg)==Items().end())
00086         {
00087             message="invalid argument for "+name+":\""+strArg+"\"";
00088             return false;
00089         }
00090         return true;
00091     }
00092 public:
00093     const vector<string> &Items(){return typeDesc->listItems;}
00094     ListArgument(XIPD::Argument &parent,ImageProcessorsDescription &_improcs):
00095         ImProcStringArgument(parent,_improcs)
00096     {
00097         if(!typeDesc){ThrowError("ListArgument::ListArgument no typeDesc");}
00098     }
00099 };
00100 
00101 
00103 
00104 class ImageProcessorDescription : public XIPD::ImageProcessor
00105 {
00106 public:
00108     vector<ImProcStringArgument *> args;
00110     ImageProcessorsDescription &improcs;
00111 public:
00113     uint size(){return args.size();}
00115     ImProcStringArgument *operator[](int i){return args[i];}
00116     int IndexOf(ImProcStringArgument *arg)
00117     {
00118         vector<ImProcStringArgument *>::iterator p=find(args.begin(),args.end(),arg);
00119         if(p==args.end()){return -1;}
00120         else{return p-args.begin();}
00121     }
00122 
00123     uint FindFullSwitch(string fs)
00124     {
00125         for(uint i=0;i<args.size();i++)
00126         {
00127             if(args[i]->FullSwitch()==fs){return i;}
00128         }       
00129         ThrowError("ImageProcessorDescription::FindFullSwitch no match for switch \"%s\"",fs);
00130         return 0;
00131     }
00132 
00134     void PrintHelp();
00135 
00137     void PrintDoxyDoc(const string& type="class head");
00138 
00140     vector<string> BuildCmdLine(const vector<string> &args0,bool stripTrailingSpaces=true);
00141     vector<string> ParseCmdLine(vector<string> cmdline);
00142     void  ValidateArguments(const vector<string> &resArgs);
00143     int ProcTemplateTypeNamePos();
00144     string ProcTemplateTypeName(vector<string> resArgs);
00145 
00147     ImageProcessorDescription(const string &_name,ImageProcessorsDescription &_improcs):
00148         XIPD::ImageProcessor(*_improcs.GetImageProcessor(_name)),
00149         improcs(_improcs)
00150     {
00151         //  create arguments
00152         for(uint i=0;i<arguments.size();i++)
00153         {
00154             args.push_back(ImProcStringArgument::Create(arguments[i],improcs));
00155         }
00156     }
00158     ~ImageProcessorDescription()
00159     {
00160         for (uint i = 0 ; i < args.size() ; i++)
00161             delete args[i];
00162     }
00163 };
00164 
00165 #endif // _ImageProcessorDescription_hpp

Generated on Fri Jun 17 13:36:04 2005 for ImLib3D by  doxygen 1.4.2