CoCoALib-0.9905 date: 23 May 2007


ServerOp.H

Go to the documentation of this file.
00001 #ifndef CoCoA_ServerOp_H
00002 #define CoCoA_ServerOp_H
00003 
00004 //   Copyright (c)  2007  John Abbott and Anna Bigatti
00005 
00006 //   This file is part of the source of CoCoALib, the CoCoA Library.
00007 
00008 //   CoCoALib is free software; you can redistribute it and/or modify
00009 //   it under the terms of the GNU General Public License (version 2)
00010 //   as published by the Free Software Foundation.  A copy of the full
00011 //   licence may be found in the file COPYING in this directory.
00012 
00013 //   CoCoALib is distributed in the hope that it will be useful,
00014 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //   GNU General Public License for more details.
00017 
00018 //   You should have received a copy of the GNU General Public License
00019 //   along with CoCoA; if not, write to the Free Software
00020 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 #include "CoCoA/SmartPtrIRC.H"
00023 #include <iosfwd>
00024 // using std::istream;
00025 // using std::ostream;
00026 #include <string>
00027 // using std::string;
00028 
00029 namespace CoCoA
00030 {
00031   //----------------------------------------------------------------------
00032   class ServerOpBase; // forward declaration for SmartPtrIRC
00033 
00034   //----------------------------------------------------------------------
00035   class ServerOp
00036   {
00037   public:
00038     explicit ServerOp(); // defined later: returns VoidOperation
00039     explicit ServerOp(ServerOpBase* ptr): mySmartPtr(ptr) {}
00040     // assignment disabled because SmartPtrIRC has no assignment
00041     ServerOpBase* operator->() { return mySmartPtr.operator->(); }  ///< Allow member fns to be called.
00042     const ServerOpBase* operator->() const { return mySmartPtr.operator->(); }  ///< Allow const member fns to be called.
00043     const ServerOpBase* myRawPtr() const { return mySmartPtr.myRawPtr(); } ///< Used by "downcasting" functions IsVoidOperation
00044     bool operator==(const ServerOp& f) const { return mySmartPtr==f.mySmartPtr; }
00045 
00046   private: // data members
00047     SmartPtrIRC<ServerOpBase> mySmartPtr;
00048   };
00049 
00050 
00051   void RegisterOp(const std::string& s, ServerOp o);
00052   ServerOp& GetOperation(const std::string& s);
00053   void CheckOperationRegistry();
00054 
00055   //----------------------------------------------------------------------
00056   class ServerOpBase: protected IntrusiveReferenceCount
00057   {
00058     friend class SmartPtrIRC<ServerOpBase>; // morally "friend ServerOp", so it can alter reference count
00059   protected:
00060     ServerOpBase() {};
00061   public:
00062     virtual ~ServerOpBase() {};
00063     virtual void myOutputSelf(std::ostream&) const = 0;
00064     virtual void myReadArgs(std::istream& in) = 0;
00065     virtual void myCompute() = 0;
00066     virtual void myWriteResult(std::ostream&) const = 0;
00067     virtual void myClear() = 0;
00068 
00069     static const std::string ourVarName4; ///< name of CoCoA4 variable which will contain the result of the computation
00070   };
00071 
00072   bool IsVoidOperation(const ServerOp& o);
00073   std::ostream& operator<<(std::ostream& out, const ServerOp& o);
00074 }
00075 
00076 // $Header: /Volumes/Home/cocoa/cvs-repository/CoCoALib-0.99/include/CoCoA/ServerOp.H,v 1.1 2007/04/27 14:54:22 bigatti Exp $
00077 // $Log: ServerOp.H,v $
00078 // Revision 1.1  2007/04/27 14:54:22  bigatti
00079 // -- content of CoCoAServer.C split into dedicated files
00080 // -- new registration mechanism (through include "RegisterServerOps.H")
00081 //
00082 
00083 #endif

Generated on Wed May 23 13:43:36 2007 for CoCoALib by  doxygen 1.4.6