00001 #ifndef _PSTACK
00002 #define _PSTACK
00003
00004 #include "global.h"
00005 #include "MercuryVector.h"
00006 #include "MercuryString.h"
00007
00009
00011 class PSElement
00012 {
00013 public:
00014 PSElement( const MString & sI ) { data.dataS = new MString(sI); type = STRING; }
00015 PSElement( const char * sI ) { data.dataS = new MString(sI); type = STRING; }
00016 PSElement( const char * sI, int Length ) { data.dataS = new MString; data.dataS->append( sI, Length ); type = STRING; }
00017 PSElement( float fI ) { data.f = fI; type = FLOAT; }
00018 PSElement( int iI ) { data.l = iI; type = INTEGER; }
00019 PSElement( unsigned iI ) { data.l = iI; type = INTEGER; }
00020 PSElement( bool bI ) { data.b = bI; type = BOOL; }
00021 PSElement( void * vI ) { data.v = vI; type = USERDATA; }
00022 PSElement( void ) { type = NIL; }
00023
00024 PSElement( const PSElement & RHS ) { data = RHS.data; type = RHS.type; if ( type == STRING ) data.dataS = new MString( *RHS.data.dataS ); }
00025 PSElement & operator = ( const PSElement & RHS ) { data = RHS.data; type = RHS.type; if ( type == STRING ) data.dataS = new MString( *RHS.data.dataS ); return *this; }
00026
00027 ~PSElement() { if ( type == STRING ) delete data.dataS; }
00028
00029 MString GetValueS() const;
00030 int GetValueI() const;
00031 float GetValueF() const;
00032 bool GetValueB() const;
00033 void * GetValueV() const;
00034
00035 inline operator MString() const { return GetValueS(); }
00036 inline operator int() const { return GetValueI(); }
00037 inline operator float() const { return GetValueF(); }
00038 inline operator bool() const { return GetValueB(); }
00039 inline operator void*() const { return GetValueV(); }
00040
00041 bool GetValueS( MString & ret );
00042 bool GetValueI( long & ret );
00043 bool GetValueF( float & ret );
00044 bool GetValueB( bool & ret );
00045 bool GetValueV( void * & ret );
00046
00047 enum ParmType
00048 {
00049 NIL = 0,
00050 BOOL,
00051 FLOAT,
00052 INTEGER,
00053 STRING,
00054 PARAMETER,
00055 USERDATA,
00056 };
00057
00058 ParmType GetType() const;
00059 void ForceType( ParmType tI ) { type = tI; }
00060 PSElement( ParmType tI ) { type = tI; }
00061
00062 PSElement Operate( const MString & sOperator, const PSElement & pRHS );
00063
00064 void SetValueF( const float fToSet ) { data.f = fToSet; }
00065 private:
00066 ParmType type;
00067 union ParmData
00068 {
00069 float f;
00070 long l;
00071 bool b;
00072 void * v;
00073 MString * dataS;
00074 } data;
00075 };
00076
00078 class PStack
00079 {
00080 public:
00081 PStack( ) { };
00082 PStack( const char * sIn, int iMaxLength = 32767 );
00083 PStack( PSElement p1 );
00084 PStack( PSElement p1, PSElement p2 );
00085 PStack( PSElement p1, PSElement p2, PSElement p3 );
00086 PStack( PSElement p1, PSElement p2, PSElement p3, PSElement p4 );
00087 ~PStack();
00088
00089 void PushItem( const PSElement & in );
00090 void PushItemBack( const PSElement & in );
00091 bool PopItem( PSElement & out );
00092 PSElement PopItem();
00093 bool PeekItem( PSElement & out );
00094 const PSElement& PeekItem( unsigned int iAhead = 0 ) const;
00095 inline const PSElement& operator[] ( unsigned int iAhead ) const { return PeekItem(iAhead); }
00096 void Clear() { m_stack.clear(); }
00097
00098 inline unsigned int GetSize() const { return m_stack.size(); }
00099 private:
00100 MVector< PSElement > m_stack;
00101 };
00102
00103
00104 int HGEXPORT CreateMPStack();
00105 int HGEXPORT GetMPStackSize( unsigned int iMPS );
00106 const char * HGEXPORT GetMPStackAtS( unsigned int iMPS, unsigned int iPL );
00107 int HGEXPORT GetMPStackAtI( unsigned int iMPS, unsigned int iPL );
00108 float HGEXPORT GetMPStackAtF( unsigned int iMPS, unsigned int iPL );
00109 void HGEXPORT PushMPStackBackS( unsigned int iMPS, const char * s );
00110 void HGEXPORT PushMPStackBackI( unsigned int iMPS, int i );
00111 void HGEXPORT PushMPStackBackF( unsigned int iMPS, float f );
00112 void HGEXPORT DeleteMPStack( unsigned int iMPS );
00113 void HGEXPORT FlushMPStacks();
00114
00115 PStack * GetMPStack( unsigned int iMPS );
00116
00117 #endif
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144