home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir04
/
f014280.re_
/
f014280.re
Wrap
Text File
|
1996-04-02
|
6KB
|
178 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1995) Bentley Systems, Inc., All rights reserved. |
| |
| "MicroStation" is a registered trademark and "MDL" and "MicroCSL" |
| are trademarks of Bentley Systems, Inc. |
| |
| Limited permission is hereby granted to reproduce and modify this |
| copyrighted material provided that the resulting code is used only |
| in conjunction with Bentley Systems products under the terms of the |
| license agreement provided therein, and that this notice is retained |
| in its entirety in any such reproduction or modification. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Logfile: J:/mdl/examples/doc/cexpr.mcv $
| $Workfile: cexpr.mc $
| $Revision: 5.2 $
| $Date: 20 Jun 1995 08:49:58 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| cexpr.mc - examples for the mdlCExpression_ functions. |
| |
| This file is intended as an adjunct to the MDL manual to |
| illustrate MDL built-in function calling conventions and parameter |
| values. While it can be compiled, it does NOT, on its own, |
| constitute a workable MDL example. |
| |
| See the files in mdl\examples\calculat for a useful example of |
| the mdlCExpression_ functions. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h>
#include <cexpr.h>
/*----------------------------------------------------------------------+
| |
| Private variables |
| |
+----------------------------------------------------------------------*/
Private void *setP;
Private CType *intPointerTypeP, *doubleArrayTypeP;
/*----------------------------------------------------------------------+
| |
| Variables to be published |
| |
+----------------------------------------------------------------------*/
int intVariable;
int *intVariable1P, *intVariable2P;
double *doubleArrayP;
/*----------------------------------------------------------------------+
| |
| name displayError |
| |
| author BSI 9/90 |
| |
| The MDL Debugger clobbers the information used by the system |
| to generate the message. If you are stepping through this |
| with the MDL debugger, the message that is generated will be |
| incorrect. |
| |
+----------------------------------------------------------------------*/
displayError (void)
{
char messageBuffer [128]; /* The message is guaranteed to be less
than 128 characters */
mdlCExpression_generateMessage (messageBuffer, mdlErrno);
mdlOutput_error (messageBuffer);
}
/*----------------------------------------------------------------------+
| |
| name hideSymbols |
| |
| author BSI 9/90 |
| |
+----------------------------------------------------------------------*/
cmdName hideSymbols
(
)
{
if (setP != NULL)
{
/* The call to mdlCExpression_freeSet frees all memory
associated with the symbol set. It frees all memory
that had been allocated by calls to
mdlCExpression_typeFromRsc, mdlCExpression_typePointer, etc */
mdlCExpression_freeSet (setP);
setP = NULL;
}
}
/*----------------------------------------------------------------------+
| |
| name publishSymbols |
| |
| author BSI 9/90 |
| |
+----------------------------------------------------------------------*/
cmdName publishSymbols
(
)
{
/* Initialize the symbol set. Set it up so that symbols that are
added to it can be recognized by the calculator. */
setP = mdlCExpression_initializeSet (VISIBILITY_CALCULATOR, 0, FALSE);
/* Create a simple variable */
mdlCExpression_symbolPublish (setP, "intVariable", SYMBOL_CLASS_VAR,
&intType, &intVariable);
/* Create a pointer variable. First define a type that can be used
for all subsequent definitions of varaibles with type pointer
to int.
*/
intPointerTypeP = mdlCExpression_typePointer (setP, &intType);
mdlCExpression_symbolPublish (setP, "pointer1", SYMBOL_CLASS_VAR,
intPointerTypeP, &intVariable1P);
mdlCExpression_symbolPublish (setP, "pointer2", SYMBOL_CLASS_VAR,
intPointerTypeP, &intVariable2P);
/* Create an array variable. */
doubleArrayP = malloc (sizeof (double) * 10);
doubleArrayTypeP = mdlCExpression_typeArray (setP, &doubleType, 10);
mdlCExpression_symbolPublish (setP, "doubleArray", SYMBOL_CLASS_VAR,
doubleArrayTypeP, doubleArrayP);
}
/*----------------------------------------------------------------------+
| |
| name evaluateExpressions |
| |
| author BSI 9/90 |
| |
+----------------------------------------------------------------------*/
cmdName evaluateExpressions
(
)
{
CExprResult result; /* Detailed result */
CExprValue value; /* Similar to result, but easier to
interpret. */
if (mdlCExpression_getValue (&value, &result, "intVariable*20",
VISIBILITY_CALCULATOR))
displayError ();
if (mdlCExpression_getValue (&value, &result, "INTVariable-10",
VISIBILITY_CALCULATOR))
displayError ();
/* The following sequence sets doubleArray [2] to 5.2 */
value.type = CEXPR_TYPE_DOUBLE;
value.val.valDouble = 5.2;
mdlCExpression_setValue (&value, NULL, "doubleArray [2]",
VISIBILITY_CALCULATOR);
/* The following sequence sets doubleArray [2] to 7.5 */
mdlCExpression_getValue (&value, &result, "doubleArray [2] = 7.5",
VISIBILITY_CALCULATOR);
}