Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

stiltimeexpr.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Copyright (c) 2006 International Business Machines Corporation
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the Common Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.opensource.org/licenses/cpl1.0.php
00007  *
00008  * Contributors:
00009  *    Douglas Sprague, Joel Wheeler - initial API and implementation
00010  *
00011  *****************************************************************************/
00012 
00013 #ifndef STILTimeExpr_H
00014 #define STILTimeExpr_H
00015 
00016 #include "stilcom.h"               // Common library
00017 #include "stilsigrefexpr.h"
00018 #include "stilnumber.h"
00019 #include "stilcomstr.h"
00020 
00021 
00022 //STILEvalEngine includes STILVectorEventList which includes STILVectorEvent.
00023 //STILVectorEvent includes STILEventList, which includes STILTimeExpr.
00024 //STILTimeExpr includes STILEvalEngine, so we need to prototype it:
00025 class STILEvalEngine; //prototype needed for compile
00026 
00027 //---------------------------------------------------------------------------
00033 //---------------------------------------------------------------------------
00034 class STILTimeExpr {
00035 
00036   // - Public members
00037   public:
00038      // Allowed operators
00039     enum Operator {
00040       UndefinedOperator,  
00041       Plus,               
00042       Minus,              
00043       LeftParen,          
00044       RightParen          
00045     };
00046 
00047    // - Default constructor
00048     STILTimeExpr();
00049 
00050     // - Copy Constructor
00051     STILTimeExpr(const STILTimeExpr &);
00052 
00053     // - Destructor
00054     ~STILTimeExpr();
00055 
00056     // - Assignment operator
00057     STILTimeExpr & operator=(const STILTimeExpr &);
00058 
00059     // - Initialize/reset this object
00060     void  init();
00061 
00062     // - Write this object out to a file
00063     virtual void write(FILE * pOutFile, LONG indentation=0) const;
00064 
00065 
00066     // - Add operators, Id's and numbers to this expression
00067     void addOp(const Operator);
00068     void addId(const sstring);
00069     void addNumber(const STILNumber&);
00070 
00071     // - Get the text of the expression
00072     // - * NOTE: If expression is empty, it will return a sstring of '' with
00073     //     length==2
00074     sstring getText() const;
00075 
00076     // - Evaluate the expression into a number/unit
00077     // Eventually TimeExpr's can have variable expressions, so an EE
00078     //   must be passed in:
00079     STILNumber eval(const STILEvalEngine & ee) const;
00080     // For now, we can only store a single STILNumber as a TimeExpr,
00081     //  so there's no need to pass in an EE:
00082     STILNumber eval() const;
00083 
00084   // - Private members
00085   private:
00086 
00087     sstring    m_text; // text representation of the string
00088 
00089     STILNumber m_snum; //start off with simple expressions- can only be a number
00090                        // (no ops)
00091 
00092 };
00093 
00094 //--------------------------------------------------------------------------
00102 //--------------------------------------------------------------------------
00103 // - Get the text of the expression
00104     // - * NOTE: If expression is empty, it will return a sstring of '' with
00105     //     length==2
00106 inline    sstring STILTimeExpr::getText() const { return ("\'"+m_text+"\'"); }
00107 
00108 //--------------------------------------------------------------------------
00116 //--------------------------------------------------------------------------
00117     // - Evaluate the expression into a number/unit
00118     // Eventually TimeExpr's can have variable expressions, so an EE
00119     //   must be passed in:
00120 inline    STILNumber STILTimeExpr::eval(const STILEvalEngine & ee) const { return m_snum; }
00121 
00122 //--------------------------------------------------------------------------
00130 //--------------------------------------------------------------------------
00131     // For now, we can only store a single STILNumber as a TimeExpr,
00132     //  so there's no need to pass in an EE:
00133 inline    STILNumber STILTimeExpr::eval() const { return m_snum; }
00134 
00135 
00136 #endif

This page last updated on 6 Jul 2007

SourceForge.net Logo