MGsProperty - top level property structure for an application
#include <libMG.h>
Data structure type MGsProperty's intended use is to declare an application's top level property structure with something like "MGsProperty propertyTopLevel;" then to set each element to a value. For example:
note: best to set propertyTopLevel.feedback with MGrCommandLine(3) but it may of course be set or adjusted elsewhere. |
MGsProperty - general idea: An application normally has several values to pass on to routines it calls. For example an application with blue title bars, a white back ground and red text would need to pass these values to any routine used for rendering. MGsProperty structure simplifies passing of top level values/properties. Simply set the values in main, then pass them on by sending the structure's address instead of each individual value. Here is an example of what to avoid:
int main() { char* id; char* ver; int background; int foregound; id = ( char* )malloc( sizeof( "application's name" ) ); ver = ( char* )malloc( sizeof( "00.00.00 or what ever the version number is" ) ); strcpy( propertyTopLevel.id, "application's name" ) strcpy( propertyTopLevel.ver, "00.00.00 or what ever the version number is" ) background = red; foreground = white; someRoutine( id, ver, background, foreground ); }
The above example of what to avoid may not seem too bad, but what if you had say 20 properties to pass? YUCK! Here is an elegant way to pass an unlimited number of properties by passing only one address and 0 properties!
int main() { MGsProperty propertyTopLevel; propertyTopLevel.id = ( char* )malloc( sizeof( "application's name" ) ); propertyTopLevel.ver = ( char* )malloc( sizeof( "00.00.00 or what ever the version number is" ) ); strcpy( propertyTopLevel.id, "application's name" ) strcpy( propertyTopLevel.ver, "00.00.00 or what ever the version number is" ) propertyTopLevel.background = red; propertyTopLevel.foreground = white; someRoutine( \&propertyTopLevel ); }
The address &propertyTopLevel is used to pass a pointer to all values stored in propertyTopLevel on down to the routine called "someRoutine". And this is how "someRoutine" would access those values:
int someRoutine( MGsProperty *propertyTopLevel ) { printf( "propertyTopLevel.id = %s", propertyTopLevel->id ); printf( "propertyTopLevel.ver = %s", propertyTopLevel->ver ); printf( "propertyTopLevel.background = %d", propertyTopLevel->background ); printf( "propertyTopLevel.foreground = %d", propertyTopLevel->foreground ); }
Notice the routine uses "->" instead of "." to access the property elements. Generally, where the property is declared use the "." and where it is passed use "->". For a detailed explanation as to why the difference, read a C tutorial.
CAUTION: The declaration of MGsProperty and its elements is located in libMG.h. Do not add too or remove any of these elements or else your program may/will become incompatable with future mojave software co. releases. |
MGsProperty sources | ||
---|---|---|
libMG.h | html | .h |
Mojave Green Software Co. Landers Ca Michael C. Shultz copyright(c) March 2004 all rights reserved