00001
00002
00003
00004 #ifndef FITYK_TPLATE_H_
00005 #define FITYK_TPLATE_H_
00006
00007 #include <vector>
00008 #include <string>
00009 #include <boost/shared_ptr.hpp>
00010
00011 #include "common.h"
00012 #include "vm.h"
00013
00014 class Settings;
00015 class Function;
00016 class Parser;
00017 struct OpTree;
00018
00019
00020
00021
00022 struct Tplate
00023 {
00024 typedef boost::shared_ptr<const Tplate> Ptr;
00025 typedef Function* (*create_type)(const Settings*, const std::string&,
00026 Ptr, const std::vector<std::string>&);
00027
00028 struct Component
00029 {
00030 Ptr p;
00031 std::vector<VMData> cargs;
00032 };
00033
00034 std::string name;
00035 std::vector<std::string> fargs;
00036 std::vector<std::string> defvals;
00037 std::string rhs;
00038 bool linear_d;
00039 bool peak_d;
00040 create_type create;
00041 std::vector<Component> components;
00042 std::vector<OpTree*> op_trees;
00043
00044 std::string as_formula() const;
00045 bool is_coded() const;
00046 std::vector<std::string> get_missing_default_values() const;
00047 };
00048
00049
00050
00051
00052 std::vector<VMData*> reorder_args(Tplate::Ptr,
00053 const std::vector<std::string> &keys,
00054 const std::vector<VMData*> &values);
00055
00056
00057 class TplateMgr
00058 {
00059 public:
00060 TplateMgr() {}
00061
00062
00063 void add_builtin_types(Parser* p);
00064
00065
00066 void define(Tplate::Ptr tp);
00067
00068
00069 void undefine(const std::string& name);
00070
00071
00072 const Tplate* get_tp(const std::string& name) const;
00073 Tplate::Ptr get_shared_tp(const std::string& name) const;
00074
00075 const std::vector<Tplate::Ptr>& tpvec() const { return tpvec_; }
00076
00077 private:
00078 std::vector<Tplate::Ptr> tpvec_;
00079
00080 void add(const char* name, const char* cs_fargs, const char* cs_dv,
00081 const char* rhs, bool linear_d, bool peak_d,
00082 Tplate::create_type create, Parser* parser=NULL);
00083
00084 DISALLOW_COPY_AND_ASSIGN(TplateMgr);
00085 };
00086
00087
00088 Function* create_CompoundFunction(const Settings* s, const std::string& name,
00089 Tplate::Ptr tp, const std::vector<std::string>& vars);
00090 Function* create_SplitFunction(const Settings* s, const std::string& name,
00091 Tplate::Ptr tp, const std::vector<std::string>& vars);
00092 Function* create_CustomFunction(const Settings* s, const std::string& name,
00093 Tplate::Ptr tp, const std::vector<std::string>& vars);
00094
00095 #endif // FITYK_TPLATE_H_