Changeset 2598 in Sophya
- Timestamp:
- Aug 11, 2004, 3:10:25 PM (21 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/cexpre.cc
r2593 r2598 68 68 //--------------------------------------------------------- 69 69 //----------- Expression changement de signe ------------- 70 /*! 71 \internal 72 \ingroup SysTools 73 \brief Class for handling change sign expression (-x) 74 \sa CExpressionEvaluator 75 */ 70 76 class CE_ChsExp : public CExprBase { 71 77 public: … … 80 86 81 87 //--------------------------------------------------------- 88 /*! 89 \internal 90 \ingroup SysTools 91 \brief Base class for binary operations on expressions 92 \sa CExpressionEvaluator 93 */ 82 94 class CE_BinExp : public CExprBase { 83 95 public: … … 119 131 120 132 //--------------------------------------------------------- 133 /*! 134 \internal 135 \ingroup SysTools 136 \brief Addition of two CExprBase (binary operation : x+y) 137 \sa CExpressionEvaluator 138 */ 121 139 class CE_AddExp : public CE_BinExp { 122 140 public: … … 125 143 } 126 144 }; 145 /*! 146 \internal 147 \ingroup SysTools 148 \brief Multiplication of two CExprBase (binary operation : x*y) 149 \sa CExpressionEvaluator 150 */ 127 151 class CE_MulExp : public CE_BinExp { 128 152 public: … … 130 154 virtual double Evaluate() const { CheckThrow("CE_MulExp::Evaluate"); return _e1->Evaluate()*_e2->Evaluate(); } 131 155 }; 156 /*! 157 \internal 158 \ingroup SysTools 159 \brief Subtraction of two CExprBase (binary operation : x-y) 160 \sa CExpressionEvaluator 161 */ 132 162 class CE_SubExp : public CE_BinExp { 133 163 public: … … 135 165 virtual double Evaluate() const { CheckThrow("CE_SubExp::Evaluate"); return _e1->Evaluate()-_e2->Evaluate(); } 136 166 }; 167 /*! 168 \internal 169 \ingroup SysTools 170 \brief Division of two CExprBase (binary operation : x/y) 171 \sa CExpressionEvaluator 172 */ 137 173 class CE_DivExp : public CE_BinExp { 138 174 public: … … 149 185 //--------------------------------------------------------- 150 186 #define FMXARG 3 187 /*! 188 \internal 189 \ingroup SysTools 190 \brief Function evaluation on other expression in the form f(), f(x), f(x,y), f(x,y,z) 191 \sa CExpressionEvaluator 192 */ 151 193 class CE_FuncExp : public CExprBase { 152 194 public: … … 169 211 170 212 // Les fonctions de generation de nombre aleatoire 171 double _CE_rand01() { return drand01(); }172 double _CE_randpm1() { return drandpm1(); }173 double _CE_gaurand() { return GauRnd(0., 1.); }213 static double _CE_rand01() { return drand01(); } 214 static double _CE_randpm1() { return drandpm1(); } 215 static double _CE_gaurand() { return GauRnd(0., 1.); } 174 216 //--------------------------------------------------------- 175 217 CE_FuncExp::CE_FuncExp(string const & func) … … 265 307 266 308 //--------------------------------------------------------- 309 /*! 310 \class CExpressionEvaluator 311 \ingroup SysTools 312 \brief Class for evaluation of arithmetic expressions with C-like syntax. 313 314 This classes can handle the parsing of c-like arithmetic 315 expressions containing numerical constants, the four 316 basic operations (addition +, subtraction -, multiplication *, 317 division /) and functions. 318 The numerical constants are also defined <tt> (Pi = M_PI E = M_E) </tt>. 319 The following functions from the standard math library and 320 random generators are available: 321 322 - sqrt fabs floor hypot 323 - exp log log10 pow 324 - sin cos tan asin acos atan atan2 325 - sinh cosh tanh 326 - rand01() : Flat random number generator in the range [0 1] 327 - randpm1() : Flat random number generator in the range [-1 1] 328 - gaurand() : Gaussian random number generator (m=0, sigma=1) 329 330 Usage example : 331 \code 332 #include "cexpre.h" 333 ... 334 string es = "4.+3*(cos(Pi/8.)+1.5)"; 335 CExpressionEvaluator e(es); 336 cout << " Expression: " << e << " = " << e.Evaluate() << endl; 337 \endcode 338 339 Output : \n 340 <tt> Expression: (4+(3*(cos((3.14159/8))+1.5))) = 11.2716 </tt> 341 */ 342 343 /*! 344 Parse the string \c sex and builds an expression. 345 Can throw CExprException exception. 346 */ 267 347 CExpressionEvaluator::CExpressionEvaluator(string const & sex) 268 348 { … … 293 373 294 374 // cette fonction rearrange le stack des operations binaires en attente 295 CExprBase* Arrange_CE_BinExpStack(stack<CE_BinExp* >& sbx, CExprBase* cex, CE_BinExp* nbx)375 static CExprBase* Arrange_CE_BinExpStack(stack<CE_BinExp* >& sbx, CExprBase* cex, CE_BinExp* nbx) 296 376 { 297 377 while ( !sbx.empty() && (nbx->Priority() <= sbx.top()->Priority()) ) { … … 305 385 306 386 // cette fonction rearrange le stack des operations binaires en attente 307 CExprBase* Arrange_CE_BinExpStack(stack<CE_BinExp* >& sbx, CExprBase* cex)387 static CExprBase* Arrange_CE_BinExpStack(stack<CE_BinExp* >& sbx, CExprBase* cex) 308 388 { 309 389 if (sbx.empty()) return cex; -
trunk/SophyaLib/SysTools/cexpre.h
r2512 r2598 14 14 namespace SOPHYA { 15 15 16 //! Exception class used by CExpressionEvaluator 16 /*! 17 \ingroup SysTools 18 \brief Exception class used by CExpressionEvaluator 19 */ 17 20 class CExprException : public PException { 18 21 public: … … 22 25 23 26 //-------------------------------------------------------------------- 24 //! Base class for arithmetic expressions used by CExpressionEvaluator 27 /*! 28 \ingroup SysTools 29 \brief Base class for arithmetic expressions used by CExpressionEvaluator 30 \sa CExpressionEvaluator 31 */ 25 32 class CExprBase { 26 33 public: … … 39 46 }; 40 47 48 /*! 49 \ingroup SysTools 50 \brief For formatted write (print) of expressions in a stream 51 */ 41 52 inline ostream& operator << (ostream& s, CExprBase const & ex) 42 53 { ex.Print(s); return(s); } … … 45 56 class CE_FuncExp; 46 57 //--------------------------------------------------------- 47 //! Class for evaluation of arithmetic expressions with C-like syntax48 58 class CExpressionEvaluator : public CExprBase { 49 59 public: 50 60 CExpressionEvaluator(string const & sex); 51 61 virtual ~CExpressionEvaluator(); 62 //! Evaluate the expression and returns the corresponding value. 52 63 virtual double Evaluate() const; 64 //! Alias for Evaluate() 53 65 inline double Value() const { return Evaluate(); } 66 //! Formatted output on a stream 54 67 virtual void Print(ostream& os) const; 55 68 56 69 protected: 70 //! Does the parsing and builds an CExprBase object. 57 71 CExprBase* ParseString(int extype, string fname, string const & sex, 58 72 size_t off, size_t& stop, string& errmsg); -
trunk/SophyaLib/SysTools/commander.cc
r2532 r2598 25 25 // ------------------------------------------------------------ 26 26 /*! 27 \internal 27 28 \class SOPHYA::CommanderBloc 28 29 \ingroup SysTools 29 Class for internal use by SOPHYA::Commander to handle loops30 Class for internal use by class Commander to handle loops 30 31 */ 31 32 class CommanderBloc { … … 253 254 254 255 /*! 256 \internal 255 257 \class SOPHYA::CommanderScript 256 258 \ingroup SysTools 257 Class for internal use by SOPHYA::Commander to handle functions259 Class for internal use by class Commander to handle functions 258 260 or scripts 259 261 */ … … 334 336 335 337 /*! 336 \class SOPHYA::Commander338 \class Commander 337 339 \ingroup SysTools 338 Simple command interpreter with c-shell like syntax and dynamic 339 load capabilities. Can be used to add scripting capabilities 340 to applications 340 \brief Simple command interpreter 341 342 This Simple command interpreter with c-shell like syntax 343 can be used to add scripting capabilities 344 to applications. 345 346 Although the insterpreter has many limitations compared to 347 c-shell, or Tcl , it provides some interesting possibilities: 348 349 - Extended arithmetic operations (c-like and RPN) 350 - Simple and vector variables 351 - Script definition 352 - Dynamic Load 353 354 \sa CmdExecutor CExpressionEvaluator RPNExpressionEvaluator 355 356 Usage example: 357 \code 358 #include "commander.h" 359 ... 360 Commander cmd; 361 char* ss[3] = {"foreach f ( AA bbb CCCC ddddd )", "echo $f" , "end"}; 362 for(int k=0; k<3; k++) { 363 string line = ss[k]; 364 cmd.Interpret(line); 365 } 366 \endcode 341 367 */ 342 368 … … 345 371 static Commander* cur_commander = NULL; 346 372 /* --Methode-- */ 373 //! Default constructor. Initializes variable list and copies \c history.pic to \c hisold.pic 347 374 Commander::Commander() 348 375 { … … 488 515 489 516 /* --Methode-- */ 517 //! Returns the string \c Commander as the interpreter's name. 490 518 string Commander::Name() 491 519 { … … 494 522 495 523 /* --Methode-- */ 524 //! Add the \b grp help group with description \b desc. 496 525 void Commander::AddHelpGroup(string& grp, string& desc) 497 526 { … … 501 530 502 531 /* --Methode-- */ 532 /*! 533 \brief Register a command executor associated with a given keyword. 534 \param keyw : keyword identifying the command 535 \param usage : the command help and usage information 536 \param ce : CmdExecutor pointer for this a command. The same object can be registered 537 multiple time for different commands. 538 \param grp : The help group corresponding to this command. 539 */ 503 540 void Commander::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string& grp) 504 541 { … … 517 554 518 555 /* --Methode-- */ 556 /*! 557 \brief Register a help text. 558 \param keyw : help keyword 559 \param usage : help text 560 \param grp : help group 561 */ 519 562 void Commander::RegisterHelp(string& keyw, string& usage, string& grp) 520 563 { … … 548 591 549 592 /* --Methode-- */ 593 /*! 594 \brief Dynamic loader for modules 595 596 A module is a shared library extending the application functionalities. 597 Typically, a module adds new commands to the interpreter. Once loaded, 598 the module is activated (initialized) by calling a function with the 599 name \b modulename_init . This function should be declared extern C 600 to avoid C++ name mangling. A cleanup function \b modulename_end 601 is called by the Commander destructor. 602 603 \param fnameso : Shared library name containing the module functions 604 and classes. 605 \param name : Module name. This string is used to form module 606 initializer and cleanup function name \c name_init \c name_end 607 */ 550 608 void Commander::LoadModule(string& fnameso, string& name) 551 609 { … … 569 627 570 628 /* --Methode-- */ 629 //! Declare a new interpreter 571 630 void Commander::AddInterpreter(CmdInterpreter * cl) 572 631 { … … 575 634 576 635 /* --Methode-- */ 636 //! Select an interpreter by its name. The corresponding Interpret method is then called 577 637 void Commander::SelInterpreter(string& name) 578 638 { … … 594 654 595 655 /* --Methode-- */ 656 /*! 657 \brief Method which has to be invoked to interpret a giev command line or string. 658 */ 596 659 int Commander::Interpret(string& s) 597 660 { … … 1894 1957 1895 1958 /* --Methode-- */ 1959 //! Produces a LaTeX file containing the registered command helps 1896 1960 void Commander::HelptoLaTeX(string const & fname) 1897 1961 { -
trunk/SophyaLib/SysTools/commander.h
r2518 r2598 27 27 // Classe definissant l'interface pour un interpreteur de commande 28 28 29 //! Interface definition for a generic command interpreter 29 /*! 30 \ingroup SysTools 31 \brief Interface definition for a generic command interpreter. 32 */ 30 33 class CmdInterpreter { 31 34 public: 32 35 virtual ~CmdInterpreter() {} ; 36 //! Returns the interpreter's name 33 37 virtual string Name()=0; 38 //! Method to be called in order to interpret a line or string. 34 39 virtual int Interpret(string& line)=0; 35 40 }; 36 41 37 42 38 //! Interface definition for command executor, to be used with SOPHYA::Commander 43 /*! 44 \ingroup SysTools 45 \brief Interface definition for command executor, to be used with Commander 46 47 A command is defined by a keyword and a number of argument 48 */ 39 49 40 50 class CmdExecutor { … … 159 169 160 170 // Pour enregistrer la liste de commandes et leurs executeurs et le help 171 //! Command executor registration - For Commander internal use 161 172 struct cmdex {int group; string us; CmdExecutor * cex; } ; 173 //! Help text registration - For Commander internal use 162 174 struct hgrpst {int gid; string desc; } ; // Identification+description d'un groupe de help 163 175 typedef map<string, hgrpst, less<string> > CmdHGroup; // Liste des groupes de commandes -
trunk/SophyaLib/SysTools/ctimer.cc
r913 r2598 1 1 // 2 // $Id: ctimer.cc,v 1. 4 2000-04-13 15:58:37ansari Exp $2 // $Id: ctimer.cc,v 1.5 2004-08-11 13:10:25 ansari Exp $ 3 3 // 4 4 … … 40 40 \class SOPHYA::Timer 41 41 \ingroup SysTools 42 \brief Simple chronometer for CPU and elapsed time measurements. 42 43 This class implements a simple chronometer which can be used for 43 44 measuring the CPU and elapsed time in functions. The constructor -
trunk/SophyaLib/SysTools/cxxcmplnk.cc
r2496 r2598 10 10 This classes handles the compilation of a C++ source code and 11 11 building of a shared library. 12 The present version has been adapted for different compilers: 13 g++ , Compaq/Digital cxx , SGI CC , KCC . 12 The present version has been adapted for different compilers and 13 systems: 14 - Linux-g++ 15 - Linux-KCC 16 - MacOS X/Darwin (Apple OS X 10.2 and 10.3) 17 - OSF-cxx : (HP/Compaq/Digital OSF-Tru64 and cxx c++ compiler) 18 - SGI-CC : Silicon Graphics system and C++ compiler 19 14 20 \sa SOPHYA::PDynLinkMgr 21 15 22 \code 16 23 #include "cxxcmplnk.h" -
trunk/SophyaLib/SysTools/pdlmgr.cc
r2498 r2598 26 26 This classes handles the run-time operations related to using shared 27 27 libraries. The present version has been adapted for different Unix 28 flavours (Linux, Compaq/Digital Unix, SGI IRIX, IBM AIX, Sun Solaris, 29 MacOS X/Darwin). 28 flavours (Linux, HP/Compaq/Digital OSF-Tru64, SGI IRIX, IBM AIX, Sun Solaris, 29 MacOS X/Darwin). \n 30 For MacOS X/Darwin, the NSxxx API 31 <tt> (NSLinkModule , NSCreateObjectFileImageFromFile, ...) </tt> 32 is used. 30 33 The example here shows the linking of shared library named "mylib.so" 31 34 containing a function \c double \c myfunction(double x). -
trunk/SophyaLib/SysTools/psighand.cc
r2508 r2598 13 13 /* Nouvelle-Fonction */ 14 14 /*!\ingroup SysTools 15 \brief Utility function for signal handling configuration. 16 15 17 Configures signal handling. When the flag is true, an exception 16 18 \b CaughtSignalExc is thrown with the excpetion id set to the -
trunk/SophyaLib/SysTools/resusage.cc
r2487 r2598 37 37 Constructor. the \b Update() method is called. 38 38 \param pg: Process group RU_Self or RU_Children or RU_All 39 - pg = RU_Self : Resource usage for the process itself 40 - pg = RU_Children : Resource usage for the child processes 41 - pg = RU_All : resource usage for the process itself and its child processes 39 42 */ 40 43 ResourceUsage::ResourceUsage(RU_ProcGrp pg) -
trunk/SophyaLib/SysTools/resusage.h
r2487 r2598 17 17 { 18 18 public: 19 /*! 20 - RU_Self : Resource usage for the process itself 21 - RU_Children : Resource usage for the child processes 22 - RU_All : resource usage for the process itself and its child processes 23 */ 19 24 enum RU_ProcGrp {RU_Self=0, RU_Children=1, RU_All=2}; 20 // RU_Self: Resource usage for the process itself 21 // RU_Children: Resource usage for the child processes 22 // RU_All: Process itself and child processes 25 23 26 ResourceUsage(RU_ProcGrp pg=RU_Self); 24 27 ~ResourceUsage(); -
trunk/SophyaLib/SysTools/rpneval.cc
r2596 r2598 10 10 11 11 /*! 12 \class SOPHYA::RPNExpressionEvaluator12 \class RPNExpressionEvaluator 13 13 \ingroup SysTools 14 14 Arithmetic expression (double precision float) evaluator 15 15 in Reverse Polish Notation (RPN). This is an HP calculator 16 16 like syntax. Space are used for separating the string 17 expression into tokens. 17 expression into tokens. \n 18 The string parsed by RPNExpressionEvaluator should be 19 formed by a set of space separated words. Each word may be 20 a numerical constant or operation or function. 21 All numeriacl constants are pushed to stack top. 22 The stack is limited only 23 by the available memory. The three numbers on the stack top 24 are referred to as <tt> x y x </tt>. \n 25 Available operations: 26 - op= + - * / % : replace (x,y) by x.op.y 27 - e pi : M_PI , M_E numerical constants 28 - f= sin cos tan asin acos atan : replace x by f(x) 29 - f= chs sqrt sq : (x<-f(x)) change-sign , square root and square (x<-x^2) operations 30 - f= log log10 exp : replace x by f(x) 31 - f= fabs floor ceiling : replace x by f(x) 32 - f= deg2rad rad2deg : replace x by f(x) 33 - f= rand01 randpm1 gaurand : pushes a random number on the stack top ([0 1] [-1 1] Gaussian) 34 - print x<>y pop push : stack operations 35 - sum product : Replace the complete stack by the sum / product of the numbers in the stack 36 - mean sigma : Replace the complete stack by the mean / sigma of the numbers in the stack 37 38 \sa CExpressionEvaluator Commander 39 40 The following output is produced by the sample code below: 41 \code 42 #include "rpneval.h" 43 ... 44 RPNExpressionEvaluator rpn1("4 2 print + 3 * "); 45 cout << "RPN1: 4 2 + 3 * -> rpn1.Value() = " << rpn1.Value() << endl; 46 RPNExpressionEvaluator rpn2("1 2 3 4 5 sum"); 47 cout << "RPN2: 1 2 3 4 5 sum -> rpn2.Value() = " << rpn2.Value() << endl; 48 \endcode 49 50 Output: 51 \verbatim 52 RPNExpressionEvaluator::PrintStack() Size()= 2 53 0: 2 (x) 54 1: 4 (y) 55 RPN1: 4 2 + 3 * -> rpn1.Value() = 18 56 RPN2: 1 2 3 4 5 sum -> rpn2.Value() = 15 57 \endverbatim 18 58 */ 19 59 60 /*! 61 \brief Parses the string \b sex into words and perform the specified operations on the stack. 62 63 Can throw RPNExprException 64 */ 20 65 RPNExpressionEvaluator::RPNExpressionEvaluator(string const & sex) 21 66 { … … 33 78 } 34 79 80 /*! 81 \brief Perform the operations specified by \b on the stack, starting from element \b exe[off]. 82 83 Can throw RPNExprException 84 */ 35 85 RPNExpressionEvaluator::RPNExpressionEvaluator(vector<string> & exe, int off) 36 86 { … … 52 102 /* Operations sur le stack RPN */ 53 103 /* --Methode-- */ 104 //! Return the stack top (x) 54 105 double RPNExpressionEvaluator::Evaluate() const 55 106 { -
trunk/SophyaLib/SysTools/rpneval.h
r2510 r2598 15 15 namespace SOPHYA { 16 16 17 //! Exception class used by RPNExpressionEvaluator 18 17 /*! 18 \ingroup SysTools 19 \brief Exception class used by RPNExpressionEvaluator 20 \sa RPNExpressionEvaluator 21 */ 19 22 class RPNExprException : public PException { 20 23 public: … … 30 33 explicit RPNExpressionEvaluator(vector<string> & exe, int off=0); 31 34 virtual ~RPNExpressionEvaluator(); 35 //! Return the stack top \c (x) as the result of the expression evaluation 32 36 virtual double Evaluate() const; // Return the value of the stack top 37 //! Alias for Evaluate() 33 38 inline double Value() const { return Evaluate(); } 34 39 35 pr otected:40 private: 36 41 int EvalRPNExpr(vector<string> & args, int off=0); 37 42 inline bool CheckStack(double& x) const -
trunk/SophyaLib/SysTools/zthread.cc
r2487 r2598 9 9 \class SOPHYA::ZThread 10 10 \ingroup SysTools 11 \brief Simple class for creating and controlling threads. 12 11 13 This class provides an interface for creating and controlling threads. 12 14 The implementation uses the POSIX thread interface. … … 130 132 \class SOPHYA::ZMutex 131 133 \ingroup SysTools 134 \brief Wrapper for Mutex objects. 135 132 136 This class implements an interface to the Mutual Exclusion objects 133 137 of the POSIX threads. … … 161 165 \class SOPHYA::ZSync 162 166 \ingroup SysTools 167 \brief Wrapper/utility class ensuring synchronised execution of an instruction bloc. 168 163 169 This class can be used to insure that the execution of a given 164 170 part of the code is synchronised, i.e. only a single thread -
trunk/SophyaLib/SysTools/zthread.h
r2496 r2598 16 16 17 17 /*! 18 \class SOPHYA::ZThreadExc18 \class ZThreadExc 19 19 \ingroup SysTools 20 This exception class is used by the classes implementing the interface 21 to the POSIX threads (\b ZThread ...) 20 \brief Exception class used by ZThread and ZMutex classes. 22 21 */ 23 22 class ZThreadExc : public PException { … … 93 92 class ZSync { 94 93 public: 94 /*! 95 Constructor. Locks the associated ZMutex. 96 97 - <tt> sigbr==1 </tt> destructor calls \c signal on 98 the associated ZMutex 99 - <tt> sigbr==2 </tt> destructor calls \c broadcast on 100 the associated ZMutex 101 */ 95 102 explicit inline ZSync(ZMutex & mtx, int sigbr=0) 96 103 {_mtx = &mtx; _sigbr = sigbr; mtx.lock(); }
Note:
See TracChangeset
for help on using the changeset viewer.