| External Variable Demo Sample Code
void ExternalVariableTest( void )
{
char theExpression[ 128 ];
long expLength;
bool keepLooping = true;
long lResult = 0;
bool bResult = false;
double dResult = 0.0;
double dReal = 0.0;
double dImag = 0.0;
char cVarType = 'X';
double dFester = 14.0;
double dpOohBaby[ 3 ][ 3 ][ 3 ];
double dRealFrodo = 22.0;
double dImagFrodo = -31.0;
double dpRealSauron[ 2 ][ 2 ];
double dpImagSauron[ 2 ][ 2 ];
char szGimli[ 16 ][ 256 ];
dpOohBaby[ 0 ][ 0 ][ 0 ] = 0;
dpOohBaby[ 0 ][ 0 ][ 1 ] = 1;
dpOohBaby[ 0 ][ 0 ][ 2 ] = 2;
dpOohBaby[ 0 ][ 1 ][ 0 ] = 10;
dpOohBaby[ 0 ][ 1 ][ 1 ] = 11;
dpOohBaby[ 0 ][ 1 ][ 2 ] = 12;
dpOohBaby[ 0 ][ 2 ][ 0 ] = 20;
dpOohBaby[ 0 ][ 2 ][ 1 ] = 21;
dpOohBaby[ 0 ][ 2 ][ 2 ] = 22;
dpOohBaby[ 1 ][ 0 ][ 0 ] = 100;
dpOohBaby[ 1 ][ 0 ][ 1 ] = 101;
dpOohBaby[ 1 ][ 0 ][ 2 ] = 102;
dpOohBaby[ 1 ][ 1 ][ 0 ] = 110;
dpOohBaby[ 1 ][ 1 ][ 1 ] = 111;
dpOohBaby[ 1 ][ 1 ][ 2 ] = 112;
dpOohBaby[ 1 ][ 2 ][ 0 ] = 120;
dpOohBaby[ 1 ][ 2 ][ 1 ] = 121;
dpOohBaby[ 1 ][ 2 ][ 2 ] = 122;
dpOohBaby[ 2 ][ 0 ][ 0 ] = 200;
dpOohBaby[ 2 ][ 0 ][ 1 ] = 201;
dpOohBaby[ 2 ][ 0 ][ 2 ] = 202;
dpOohBaby[ 2 ][ 1 ][ 0 ] = 210;
dpOohBaby[ 2 ][ 1 ][ 1 ] = 211;
dpOohBaby[ 2 ][ 1 ][ 2 ] = 212;
dpOohBaby[ 2 ][ 2 ][ 0 ] = 220;
dpOohBaby[ 2 ][ 2 ][ 1 ] = 221;
dpOohBaby[ 2 ][ 2 ][ 2 ] = 222;
dpRealSauron[ 0 ][ 1 ] = 2000;
dpImagSauron[ 0 ][ 1 ] = -3000;
lzCreatePublicContext( "ExtVarTstContext" );
lzSetContext( "ExtVarTstContext", false );
lzSetNumVar( 'G', "wazoo", 13.0 );
lzLinkNumVar( 'G', "fester", &dFester );
lzCreateNumArray( 'G', "hodaddy", 2, 2, 2, 0, 0, 0, 0 );
lzSetNumArrayElement( 'G', "hodaddy", 1959.05, 2, 0, 1, 0, 0, 0, 0 );
lzSetNumArrayElement( 'G', "hodaddy", 1958.05, 2, 1, 0, 0, 0, 0, 0 );
lzLinkNumArray( 'G', "oohbaby", (double*)dpOohBaby, 3, 3, 3, 3, 0, 0, 0 );
//lzSetComplexVar( 'G', "bilbo", 111.0, -37.2 );
lzSetRealVar( 'G', "bilbo", 111.0 );
lzSetImagVar( 'G', "bilbo", -37.2 );
lzLinkComplexVar( 'G', "frodo", &dRealFrodo, &dImagFrodo );
lzCreateComplexArray( 'G', "gandalf", 2, 2, 2, 0, 0, 0, 0 );
lzSetComplexArrayElement( 'G', "gandalf", 1959.05, 14, 2, 0, 1, 0, 0, 0, 0 );
//lzSetComplexArrayElement( 'G', "gandalf", 1958.05, 1, 2, 1, 0, 0, 0, 0, 0 );
lzSetRealArrayElement( 'G', "gandalf", 1958.05, 2, 1, 0, 0, 0, 0, 0 );
lzSetImagArrayElement( 'G', "gandalf", 1, 2, 1, 0, 0, 0, 0, 0 );
lzLinkComplexArray( 'G', "sauron", (double*)dpRealSauron, (double*)dpImagSauron, 2, 2, 2, 0, 0, 0, 0 );
lzLinkStrArray( 'G', "gimli", (char*)szGimli, 256, 1, 16, 0, 0, 0, 0, 0 );
lzCreateStrArray( 'G', "ringo", 32, 1, 10, 0, 0, 0, 0, 0);
lzSetStrArrayElement( 'G', "ringo", "starr", 1, 4, 0, 0, 0, 0, 0 );
lzCreateStrVar( 'C', "samwise", 256 );
dResult = lzGetNumVarValue( 'G', "wazoo" );
dResult = lzGetNumVarValue( 'G', "fester" );
dResult = lzGetNumArrayElement( 'G', "hodaddy", 2, 0, 1, 0, 0, 0, 0 );
dResult = lzGetNumArrayElement( 'G', "hodaddy", 2, 1, 0, 0, 0, 0, 0 );
dResult = lzGetNumArrayElement( 'G', "oohbaby", 3, 1, 2, 0, 0, 0, 0 );
lResult = lzDeleteVar( 'G', "bilbo" );
bResult = lzGetComplexVarValue( 'G', "bilbo", &dReal, &dImag );
bResult = lzGetComplexVarValue( 'G', "frodo", &dReal, &dImag );
bResult = lzGetComplexArrayElement( 'G', "gandalf", &dReal, &dImag, 2, 0, 1, 0, 0, 0, 0 );
bResult = lzGetComplexArrayElement( 'G', "gandalf", &dReal, &dImag, 2, 1, 0, 0, 0, 0, 0 );
bResult = lzGetComplexArrayElement( 'G', "sauron", &dReal, &dImag, 2, 0, 1, 0, 0, 0, 0 );
bResult = lzSetBoolVar( 'G', "gollum", false );
bResult = lzGetBoolVarValue( 'G', "gollum" );
bResult = lzSetBoolVar( 'G', "gollum", true );
bResult = lzGetBoolVarValue( 'G', "gollum" );
bResult = lzIsVar( 'G', "oddjob" );
bResult = lzIsVar( 'C', "gollum" );
bResult = lzIsVar( 'A', "gollum" );
cVarType = lzGetVarType( 'C', "oddjob" );
cVarType = lzGetVarType( 'G', "gollum" );
cVarType = lzGetVarType( 'A', "gandalf" );
cVarType = lzGetVarType( 'A', "bilbo" );
while ( keepLooping )
{
GetInputString( theExpression, 128 );
expLength = strlen( theExpression );
if ( expLength == 0 )
keepLooping = false;
else if ( (expLength == 1) && (theExpression[ 0 ] == '\r') )
keepLooping = false;
else if (theExpression[ 0 ] == '\\')
keepLooping = false;
else
{
cout << " " << lzEvalExpStrToStr( theExpression ) << '\n';
if ( lzGetLastErrorID() )
cout << lzGetLastErrorText() << '\n';
cout.flush();
}
}
lzDestroyPublicContext( "ExtVarTstContext" );
}
|