FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
TCLObjectProcessor.h
1 /*
2  This software is Copyright by the Board of Trustees of Michigan
3  State University (c) Copyright 2005.
4 
5  You may use this software under the terms of the GNU public license
6  (GPL). The terms of this license are described at:
7 
8  http://www.gnu.org/licenses/gpl.txt
9 
10  Author:
11  Ron Fox
12  NSCL
13  Michigan State University
14  East Lansing, MI 48824-1321
15 */
16 
17 #ifndef TCLOBJECTPROCESSOR_H
18 #define TCLOBJECTPROCESSOR_H
19 
20 #ifndef TCLINTERPRETEROBJECT_H
21 #include <TCLInterpreterObject.h>
22 #endif
23 
24 #ifndef TCLOBJECT_H
25 #include <TCLObject.h>
26 #endif
27 
28 #include <tcl.h>
29 #include <vector>
30 
31 // Forward class definitions:
32 
33 class CTCLInterpreter;
34 
45 {
46  // Attributes:
47 
48 private:
49  Tcl_Command m_Token; // Command token.
50  bool m_fRegistered; // True if command was registered.
51  std::string m_Name; // Initial name of the command.
52 public:
53  // Constructors and other canonical operations:
54 
56  std::string name,
57  bool registerMe=true);
58  virtual ~CTCLObjectProcessor();
59  // Illegal canonicals:
60 private:
62  CTCLObjectProcessor& operator=(const CTCLObjectProcessor& rhs);
63  int operator==(const CTCLObjectProcessor& rhs) const;
64  int operator!=(const CTCLObjectProcessor& rhs) const;
65 public:
66 
67  // class operations:
68 
69 public:
70  void Register(); // Register command on the interpreter.
71  Tcl_Command RegisterAs(std::string name); // register with a specific name.
72  void unregister(); // Unregister command from the interp.
73  void unregisterAs(Tcl_Command token); // unregister given command token.
74  std::string getName() const; // Return the name of the object.
75  Tcl_CmdInfo getInfo() const; // Return info about the command.
76 
77  // Replaceable functionality:0
78 
79 protected:
80  virtual int operator()(CTCLInterpreter& interp,
81  std::vector<CTCLObject>& objv) = 0;
82  virtual void onUnregister();
83 
84  // Useful methods for derived classes:
85 
86 protected:
87  void bindAll(CTCLInterpreter& interp, std::vector<CTCLObject>& objv);
88  void requireAtLeast(std::vector<CTCLObject>& objv, unsigned n, const char* msg=0) const;
89  void requireAtMost(std::vector<CTCLObject>& objv, unsigned n, const char* msg=0) const;
90  void requireExactly(std::vector<CTCLObject>& objv, unsigned n, const char* msg=0) const;
91 
92 
93  // Static callback relays:
94 
95 private:
96  static int commandRelay(ClientData pObject, Tcl_Interp* pInterp,
97  int objc, Tcl_Obj* const* objv);
98  static void unregisterRelay(ClientData pObject);
99 
100 };
101 
102 
103 #endif
void unregisterAs(Tcl_Command token)
Definition: TCLObjectProcessor.cpp:124
Definition: TCLInterpreterObject.h:46
Definition: TCLInterpreter.h:59
void bindAll(CTCLInterpreter &interp, std::vector< CTCLObject > &objv)
Definition: TCLObjectProcessor.cpp:200
void requireAtLeast(std::vector< CTCLObject > &objv, unsigned n, const char *msg=0) const
Definition: TCLObjectProcessor.cpp:217
void unregister()
Definition: TCLObjectProcessor.cpp:107
void Register()
Definition: TCLObjectProcessor.cpp:74
Definition: TCLObjectProcessor.h:44
std::string getName() const
Definition: TCLObjectProcessor.cpp:141
Tcl_CmdInfo getInfo() const
Definition: TCLObjectProcessor.cpp:164
void requireExactly(std::vector< CTCLObject > &objv, unsigned n, const char *msg=0) const
Definition: TCLObjectProcessor.cpp:255
virtual ~CTCLObjectProcessor()
Definition: TCLObjectProcessor.cpp:60
void requireAtMost(std::vector< CTCLObject > &objv, unsigned n, const char *msg=0) const
Definition: TCLObjectProcessor.cpp:236
Tcl_Command RegisterAs(std::string name)
Definition: TCLObjectProcessor.cpp:89
virtual void onUnregister()
Definition: TCLObjectProcessor.cpp:273