00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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;
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
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