File indexing completed on 2025-12-15 10:20:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef _Draw_Interpretor_HeaderFile
0018 #define _Draw_Interpretor_HeaderFile
0019
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Macro.hxx>
0023 #include <Standard_Boolean.hxx>
0024 #include <Draw_PInterp.hxx>
0025 #include <Standard_SStream.hxx>
0026 #include <Standard_Real.hxx>
0027
0028 class TCollection_AsciiString;
0029 class TCollection_ExtendedString;
0030
0031
0032 class Draw_Interpretor
0033 {
0034
0035 public:
0036
0037
0038 typedef Standard_Integer (*CommandFunction )(Draw_Interpretor& theDI,
0039 Standard_Integer theArgNb,
0040 const char** theArgVec);
0041
0042
0043 struct CallBackData
0044 {
0045
0046
0047 CallBackData (Draw_Interpretor* theDI) : myDI (theDI) {}
0048
0049
0050 virtual ~CallBackData() {}
0051
0052
0053 virtual Standard_Integer Invoke (Draw_Interpretor& theDI,
0054 Standard_Integer theArgNb,
0055 const char** theArgVec) = 0;
0056
0057 Draw_Interpretor* myDI;
0058
0059
0060 DEFINE_STANDARD_ALLOC
0061
0062 };
0063
0064 protected:
0065
0066
0067 struct CallBackDataFunc : public CallBackData
0068 {
0069
0070 CallBackDataFunc (Draw_Interpretor* theDI,
0071 CommandFunction theFunc)
0072 : CallBackData (theDI),
0073 myFunc (theFunc) {}
0074
0075 virtual Standard_Integer Invoke (Draw_Interpretor& theDI,
0076 Standard_Integer theArgNb,
0077 const char** theArgVec)
0078 {
0079 return myFunc != NULL ? myFunc (theDI, theArgNb, theArgVec) : 1;
0080 }
0081
0082 Draw_Interpretor::CommandFunction myFunc;
0083
0084 };
0085
0086
0087 template<typename theObjHandle>
0088 struct CallBackDataMethod : public CallBackData
0089 {
0090 typedef typename theObjHandle::element_type element_type;
0091 typedef Standard_Integer (element_type::*methodType)(Draw_Interpretor& , Standard_Integer , const char** );
0092
0093 CallBackDataMethod (Draw_Interpretor* theDI,
0094 const theObjHandle& theObjPtr,
0095 methodType theMethod)
0096 : CallBackData (theDI),
0097 myObjPtr (theObjPtr),
0098 myMethod (theMethod) {}
0099
0100 virtual Standard_Integer Invoke (Draw_Interpretor& theDI,
0101 Standard_Integer theArgNb,
0102 const char** theArgVec)
0103 {
0104 return myMethod != NULL && !myObjPtr.IsNull()
0105 ? (myObjPtr.operator->()->*myMethod) (theDI, theArgNb, theArgVec)
0106 : 1;
0107 }
0108
0109 theObjHandle myObjPtr;
0110 methodType myMethod;
0111
0112 };
0113
0114 public:
0115
0116
0117 Standard_EXPORT Draw_Interpretor();
0118
0119
0120 Standard_EXPORT void Init();
0121
0122
0123
0124 inline void Add (Standard_CString theCommandName,
0125 Standard_CString theHelp,
0126 CommandFunction theFunction,
0127 Standard_CString theGroup = "User Commands")
0128 {
0129 Add (theCommandName, theHelp, "", theFunction, theGroup);
0130 }
0131
0132
0133
0134
0135 inline void Add (Standard_CString theCommandName,
0136 Standard_CString theHelp,
0137 Standard_CString theFileName,
0138 CommandFunction theFunction,
0139 Standard_CString theGroup = "User Commands")
0140 {
0141 CallBackDataFunc* aCallback = new CallBackDataFunc (this, theFunction);
0142 add (theCommandName, theHelp, theFileName, aCallback, theGroup);
0143 }
0144
0145
0146
0147
0148
0149 template<typename theHandleType>
0150 inline void Add (Standard_CString theCommandName,
0151 Standard_CString theHelp,
0152 Standard_CString theFileName,
0153 const theHandleType& theObjPtr,
0154 typename Draw_Interpretor::CallBackDataMethod<theHandleType>::methodType theMethod,
0155 Standard_CString theGroup)
0156 {
0157 Draw_Interpretor::CallBackDataMethod<theHandleType>* aCallback =
0158 new Draw_Interpretor::CallBackDataMethod<theHandleType> (this, theObjPtr, theMethod);
0159 add (theCommandName, theHelp, theFileName, aCallback, theGroup);
0160 }
0161
0162
0163 Standard_EXPORT Standard_Boolean Remove (const Standard_CString theCommandName);
0164
0165 public:
0166
0167 Standard_EXPORT Standard_CString Result() const;
0168
0169
0170 Standard_EXPORT void Reset();
0171
0172
0173 Standard_EXPORT Draw_Interpretor& Append (const Standard_CString theResult);
0174 inline Draw_Interpretor& operator<< (const Standard_CString theResult) { return Append (theResult); }
0175
0176
0177 Standard_EXPORT Draw_Interpretor& Append (const TCollection_AsciiString& theResult);
0178 inline Draw_Interpretor& operator<< (const TCollection_AsciiString& theResult) { return Append (theResult); }
0179
0180
0181 Standard_EXPORT Draw_Interpretor& Append (const TCollection_ExtendedString& theResult);
0182 inline Draw_Interpretor& operator<< (const TCollection_ExtendedString& theResult) { return Append (theResult); }
0183
0184
0185 Standard_EXPORT Draw_Interpretor& Append (const Standard_Integer theResult);
0186 inline Draw_Interpretor& operator<< (const Standard_Integer theResult) { return Append (theResult); }
0187
0188
0189 Standard_EXPORT Draw_Interpretor& Append (const Standard_Real theResult);
0190 inline Draw_Interpretor& operator<< (const Standard_Real theResult) { return Append (theResult); }
0191
0192
0193 Standard_EXPORT Draw_Interpretor& Append (const Standard_SStream& theResult);
0194 inline Draw_Interpretor& operator<< (const Standard_SStream& theResult) { return Append (theResult); }
0195
0196
0197 Standard_EXPORT void AppendElement (const Standard_CString theResult);
0198
0199
0200 Standard_EXPORT Standard_Integer Eval (const Standard_CString theScript);
0201
0202
0203
0204 Standard_EXPORT Standard_Integer RecordAndEval (const Standard_CString theScript,
0205 const Standard_Integer theFlags = 0);
0206
0207
0208 Standard_EXPORT Standard_Integer EvalFile (const Standard_CString theFileName);
0209
0210
0211 Standard_EXPORT Standard_Integer PrintHelp (const Standard_CString theCommandName);
0212
0213
0214 Standard_EXPORT static Standard_Boolean Complete (const Standard_CString theScript);
0215
0216 public:
0217
0218
0219 Standard_EXPORT ~Draw_Interpretor();
0220
0221 Standard_EXPORT Draw_Interpretor (const Draw_PInterp& theInterp);
0222
0223 Standard_EXPORT void Set (const Draw_PInterp& theInterp);
0224
0225 Standard_EXPORT Draw_PInterp Interp() const;
0226
0227
0228 Standard_EXPORT void SetDoLog (const Standard_Boolean theDoLog);
0229
0230
0231 Standard_EXPORT void SetDoEcho (const Standard_Boolean theDoEcho);
0232
0233
0234 Standard_EXPORT Standard_Boolean GetDoLog() const;
0235
0236
0237 Standard_EXPORT Standard_Boolean GetDoEcho() const;
0238
0239
0240 Standard_EXPORT void ResetLog();
0241
0242
0243
0244 Standard_EXPORT void AddLog (const Standard_CString theStr);
0245
0246
0247 Standard_EXPORT TCollection_AsciiString GetLog();
0248
0249
0250 Standard_Integer GetLogFileDescriptor() { return myFDLog; }
0251
0252
0253 Standard_Boolean ToColorize() const { return myToColorize; }
0254
0255
0256 Standard_EXPORT void SetToColorize (Standard_Boolean theToColorize);
0257
0258 protected:
0259
0260 Standard_EXPORT void add (Standard_CString theCommandName,
0261 Standard_CString theHelp,
0262 Standard_CString theFileName,
0263 CallBackData* theCallback,
0264 Standard_CString theGroup);
0265
0266 private:
0267
0268 Draw_PInterp myInterp;
0269 Standard_Boolean isAllocated;
0270 Standard_Boolean myDoLog;
0271 Standard_Boolean myDoEcho;
0272 Standard_Boolean myToColorize;
0273 Standard_Integer myFDLog;
0274
0275 public:
0276
0277 DEFINE_STANDARD_ALLOC
0278
0279 };
0280
0281 #endif