ReturnInstruction.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/calculator/ReturnInstruction.h#5 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2004-2009 SQLstream, Inc.
00006 // Copyright (C) 2009-2009 LucidEra, Inc.
00007 //
00008 // This program is free software; you can redistribute it and/or modify it
00009 // under the terms of the GNU General Public License as published by the Free
00010 // Software Foundation; either version 2 of the License, or (at your option)
00011 // any later version approved by The Eigenbase Project.
00012 //
00013 // This program 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 this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 //
00022 // ReturnInstruction
00023 //
00024 // Instruction->ReturnInstruction
00025 //
00026 // Template for all native types
00027 */
00028 #ifndef Fennel_ReturnInstruction_Included
00029 #define Fennel_ReturnInstruction_Included
00030 
00031 #include "fennel/calculator/Instruction.h"
00032 
00033 FENNEL_BEGIN_NAMESPACE
00034 
00035 class FENNEL_CALCULATOR_EXPORT ReturnInstruction
00036     : public Instruction
00037 {
00038 public:
00039     explicit
00040     ReturnInstruction() {}
00041 
00042     virtual
00043     ~ReturnInstruction() {}
00044 
00045     virtual void exec(TProgramCounter& pc) const {
00046         // Force pc past end of program
00047         pc = TPROGRAMCOUNTERMAX;
00048     }
00049 
00050     static const char * longName()
00051     {
00052         return "Return";
00053     }
00054 
00055     static const char * shortName()
00056     {
00057         return "RETURN";
00058     }
00059 
00060     static int numArgs()
00061     {
00062         return 0;
00063     }
00064 
00065     void describe(string& out, bool values) const {
00066         out = longName();
00067     }
00068 
00069     static InstructionSignature
00070     signature() {
00071         return InstructionSignature(shortName());
00072     }
00073 
00074     static Instruction*
00075     create(InstructionSignature const & sig)
00076     {
00077         assert(sig.size() == numArgs());
00078         return new ReturnInstruction();
00079     }
00080 };
00081 
00088 class FENNEL_CALCULATOR_EXPORT RaiseInstruction
00089     : public Instruction
00090 {
00091 public:
00092     explicit
00093     RaiseInstruction(RegisterRef<char*>* code) :
00094         mCode(code)
00095     {}
00096 
00097     virtual
00098     ~RaiseInstruction() {}
00099 
00100     virtual void exec(TProgramCounter& pc) const {
00101         pc++;
00102         if (!mCode->isNull()) {
00103             throw CalcMessage(mCode->pointer(), pc - 1);
00104         }
00105     }
00106 
00107     static const char * longName()
00108     {
00109         return "Raise";
00110     }
00111 
00112     static const char * shortName()
00113     {
00114         return "RAISE";
00115     }
00116 
00117     static int numArgs()
00118     {
00119         return 1;
00120     }
00121 
00122     void describe(string& out, bool values) const {
00123         out = longName();
00124     }
00125 
00126     static InstructionSignature
00127     signature(StandardTypeDescriptorOrdinal type) {
00128         vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00129         return InstructionSignature(shortName(), v);
00130     }
00131 
00132     static Instruction*
00133     create(InstructionSignature const & sig)
00134     {
00135         assert(sig.size() == numArgs());
00136         return new
00137             RaiseInstruction(static_cast<RegisterRef<char*>*> (sig[0]));
00138     }
00139 private:
00140     RegisterRef<char*>* mCode;
00141 };
00142 
00143 class FENNEL_CALCULATOR_EXPORT ReturnInstructionRegister
00144     : InstructionRegister {
00145 public:
00146     static void
00147     registerInstructions()
00148     {
00149         // Shortcut registration system, as there are neither args nor types.
00150         StringToCreateFn* instMap = InstructionFactory::getInstructionTable();
00151         (*instMap)[ReturnInstruction::signature().compute()] =
00152             &ReturnInstruction::create;
00153 
00154         // Again, shortcut for RAISE, which has simple needs
00155         InstructionRegister::registerInstance
00156             < char*, fennel::RaiseInstruction >
00157             (STANDARD_TYPE_VARCHAR);
00158     }
00159 };
00160 
00161 
00162 
00163 FENNEL_END_NAMESPACE
00164 
00165 #endif
00166 
00167 // End ReturnInstruction.h
00168 

Generated on Mon Jun 22 04:00:17 2009 for Fennel by  doxygen 1.5.1