00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __OP_OperatorTable_h__
00021 #define __OP_OperatorTable_h__
00022
00023 #include "OP_API.h"
00024 #include <UT/UT_String.h>
00025 #include <UT/UT_SymbolTable.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include "OP_OTLDefinition.h"
00028 #include "OP_Operator.h"
00029
00030 class OP_Node;
00031 class OP_Network;
00032 class OP_OperatorTable;
00033 class OP_ScriptOperator;
00034 class OP_ScriptIndexFile;
00035 class OP_UpdateTableSink;
00036
00037 typedef UT_PtrArray<OP_OperatorTable *> OP_OperatorTableList;
00038 typedef OP_ScriptOperator *(*OP_ScriptCreatorFunc)
00039 (const OP_OTLDefinition &definition);
00040
00041 class OP_API OP_OperatorTable : private UT_SymbolTable
00042 {
00043 public:
00044 OP_OperatorTable(const char *table_name, const char *script_directory);
00045 ~OP_OperatorTable();
00046
00047 static int getAllOperatorTables(OP_OperatorTableList &list);
00048
00049 OP_Node *createNode(OP_Network *parent, const char *type,
00050 const char *name = 0,
00051 int *aliasedScriptedOp = 0);
00052
00053 OP_Operator *getOperator(const char *name);
00054 int addOperator(OP_Operator *op);
00055 void removeOperator(OP_Operator *op);
00056
00057 OP_Operator *getPrimarySubnetOperator()
00058 { return myPrimarySubnet; }
00059
00060 void setScriptCreator(OP_ScriptCreatorFunc func);
00061 void addScriptIndexFile(const char *indexpath,
00062 const char *indexfile,
00063 const char *classid,
00064 const char *extrainfo,
00065 int defaultMinInputs,
00066 int defaultMaxInputs,
00067 bool issubnet,
00068 bool ispython);
00069 bool loadScriptOperator(const char *opname, UT_IStream &is,
00070 OP_OTLLibrary *addToLib);
00071 bool addOperatorIfNew(const OP_OTLDefinition &definition);
00072
00073 void requestReload();
00074
00075
00076
00077 void runDSOInstall();
00078
00079
00080 bool loadDSO(const char *dso_file);
00081
00082 int entries() const { return myOpCount; }
00083
00084 int getOperatorList(UT_StringList &list, int english=1);
00085 int getOperators(OP_OperatorList &list,
00086 OP_Network *net = 0,
00087 bool filterhidden = false);
00088
00089
00090 OP_OpTypeId getOpTypeID() const;
00091
00092
00093 int getUniqueOpTypeID() const { return myUniqueOpTypeID; }
00094
00095 void sortOperators(OP_OperatorList &list,
00096 OP_Operator::OP_OperatorCompare method =
00097 OP_Operator::OP_COMPARE_GEN_NAME);
00098
00099 const UT_String &getName() const { return myName; }
00100 const UT_String &getScriptPath() const { return myScriptDirectory; }
00101
00102 unsigned getOperatorStatus(OP_Operator *op) const;
00103 unsigned getStatus(void) const;
00104 void setDefaultType(const char *type);
00105 const char *getDefaultType() const;
00106
00107
00108 bool setOpRename(const char *optype, const char *newname);
00109
00110 void outputOpRenames(ostream &os) const;
00111
00112 bool setOpAlias(const char *original, const char *alias);
00113
00114 void outputOpAliases(ostream &os) const;
00115
00116 void getOpAliases(const char *opname,
00117 UT_StringArray &opaliases) const;
00118
00119 const char *getOpFromAlias(const char *alias) const;
00120
00121 bool addOpExcluded(const char *opname);
00122
00123 bool isOpExcluded(const char *opname);
00124
00125 void outputOpExcluded(ostream &os) const;
00126
00127 void addOpHidden(const char *opname);
00128
00129 void delOpHidden(const char *opname);
00130
00131 bool isOpHidden(const char *opname);
00132
00133 void outputOpHidden(ostream &os) const;
00134
00135
00136
00137
00138 void getDefaultTypeName(const char *type, UT_String &name);
00139
00140
00141
00142 const char *getScriptedSubnetIndex() const;
00143
00144
00145
00146
00147 void notifyUpdateTableSinksOfUpdate();
00148
00149 static inline int getLoadDSOFlag() { return theLoadDSOFlag; }
00150 static inline void setLoadDSOFlag(int i) { theLoadDSOFlag = i; }
00151 static unsigned getPermissionMask(const OP_Operator *op);
00152 static void clearPermissionMask(const OP_Operator *op);
00153
00154 private:
00155
00156 void addUpdateTableSink(OP_UpdateTableSink *sink);
00157 void removeUpdateTableSink(OP_UpdateTableSink *sink);
00158
00159 void notifyUpdateTableSinksOfDelete();
00160
00161
00162 OP_ScriptOperator *addNewOperator(const OP_OTLDefinition &definition);
00163 int loadScriptIndexFile(OP_ScriptIndexFile &sif,
00164 bool checkdup);
00165
00166 UT_String myName;
00167 UT_String myScriptDirectory;
00168 UT_String myDefaultType;
00169 UT_String myScriptedSubnetIndex;
00170 OP_Operator *myPrimarySubnet;
00171 int myOpCount;
00172 int myUniqueOpTypeID;
00173 static int theLoadDSOFlag;
00174
00175 OP_ScriptCreatorFunc myScriptCreatorFunc;
00176 UT_PtrArray<OP_ScriptIndexFile *> myScriptIndexFiles;
00177 UT_PtrArray<OP_UpdateTableSink *> myUpdateTableSinks;
00178 UT_SymbolTable myOpRenames;
00179 UT_SymbolTable myOpAliases;
00180 UT_StringArray myExcludedOps;
00181 UT_StringArray myHiddenOps;
00182
00183 friend class OP_UpdateTableSink;
00184 };
00185
00186 class OP_API OP_UpdateTableSink
00187 {
00188 public:
00189 OP_UpdateTableSink() { }
00190 virtual ~OP_UpdateTableSink()
00191 { removeAllTableSinks(); }
00192
00193 virtual void tableUpdated(OP_OperatorTable *table) = 0;
00194 virtual void tableDeleted(OP_OperatorTable *table)
00195 { removeUpdateTableSink(table); }
00196
00197 protected:
00198 void addUpdateTableSink(OP_OperatorTable *table)
00199 {
00200 if( !table ) return;
00201 table->addUpdateTableSink(this);
00202 myOpTables.append(table, 1);
00203 }
00204 void removeUpdateTableSink(OP_OperatorTable *table)
00205 {
00206 if( !table ) return;
00207 table->removeUpdateTableSink(this);
00208 myOpTables.remove(table);
00209 }
00210 void removeAllTableSinks()
00211 {
00212 for( int i = myOpTables.entries(); i --> 0; )
00213 removeUpdateTableSink(myOpTables(i));
00214 }
00215
00216 private:
00217 OP_OperatorTableList myOpTables;
00218 };
00219
00220 #endif