📄 int_value.h
字号:
/*..........................................................................*//* *//* L a s t W a v e K e r n e l 3 . 0 *//* *//* Copyright (C) 1998-2002 Emmanuel Bacry. *//* email : lastwave@cmap.polytechnique.fr *//* *//*..........................................................................*//* *//* This program is a free software, you can redistribute it and/or *//* modify it under the terms of the GNU General Public License as *//* published by the Free Software Foundation; either version 2 of the *//* License, or (at your option) any later version *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program (in a file named COPYRIGHT); *//* if not, write to the Free Software Foundation, Inc., *//* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* *//*..........................................................................*//****************************************************************************//* *//* int_value.h This file contains the VALUE definition *//* *//****************************************************************************/#ifndef VALUE_H#define VALUE_H /* * Abstract structure for the content of a variable * * Any structure you want to be a variable should start with the * following fields. * * WARNING : If you change it, you should change the definition in int_hash.h */#define ValueFields \ struct typeStruct *ts; \ void * (*sendMessage) (void *content,int message,void **arg); \ short nRef typedef struct value { ValueFields; } *VALUE;/* * The method list structure to access fields */typedef struct field { char *name; /* * The Get function : void *Get(struct value * vc, void **arg); * * arg[0] = fieldName (NULL if extraction on the object itself) * arg[1] = The eventual FSIList for extraction * arg[2] = a pointer to the result if LWFLOAT * arg[3] = a pointer to the result if string * arg[4] = a pointer to the result if not a LWFLOAT * * If an VALUE is returned (in arg[4]), you should manage the total nRef. * Thus if it is a VALUE that you created just to answer the message * you should just make it temporary. If you had the VALUE before, just * add 1 reference and make it temporary * * Same thing for strings : if it is a string that was already allocated, you * don't need to do anything otherwise you have to make it temporary * * Returns NULL if field does not exist (use SetErrorf to set the error). * Otherwise, returns the type of the result. */ void *Get; /* * The Set function : void *Set(struct value * vc, void **arg); * * arg[0] = fieldName to be set * arg[1] = The eventual FSIList associated to this field * arg[2] = a pointer to the value if LWFLOAT * arg[3] = a pointer to the value if string * arg[4] = a pointer to the value if not a string nor a LWFLOAT * arg[5] = a pointer to a char which indicates whether := was used or not * Returns NULL if field does not exist (use SetErrorf to set the error) */ void *Set; /* * The ExtractOptions function : void *ExtractOptions(struct value * vc, void **arg); * * arg[0] = fieldName (NULL if extraction on the object itself) * Returns the options (NULL terminated array of strings, e.g. *nolimit,...) associated to * the specified field. * returns NULL if no extraction is available */ void *ExtractOptions; /* * The ExtractInfo function : void *ExtractInfo(struct value * vc, void **arg); * * arg[0] = fieldName (NULL if extraction on the object itself) * arg[1] = &options (a pointer to the options mask --> type is unsigend long *) * Returns the info structure (ExtractInfo *) associated to the field and the * options (fieldName can be NULL if extraction of the object itself is performed) * Returns NULL if no extraction is available */ void *ExtractInfo; } Field;/* * The type structure of a VALUE */typedef struct typeStruct { /* The documentation on this type */ char *doc; /* The basic (unique) type name */ char **type; /* The GetType function */ char * (*GetType)(struct value *vc); /* The Delete function : void Delete(VALUE val) */ void *Delete; /* The New function : VALUE New(void) */ void *New; /* The Copy function : VALUE Copy (VALUE in, VALUE out) */ void *Copy; /* The Clear function void Clear(VALUE in) */ void *Clear; /* Convert the object into a string "short" or "normal" : char *ToStr(VALUE val, char flagShort) */ void *ToStr; /* The LongPrint function : print the object when 'print' is called : void Print(VALUE val) */ void *Print; /* The PrintInfo function : called by 'info' : void PrintInfo(VALUE val) */ void *PrintInfo; /* * The NumExtract function : used to deal with syntax like 10a : void NumExtract(VALUE val, void **arg) * * arg[0] = an integer * arg[1] = a flag that indicates whether a '.' was find * arg[2] = a pointer to the result if LWFLOAT * arg[3] = a pointer to the result if string (should be allocated) * arg[4] = a pointer to the result if not a string or a LWFLOAT * Returns NULL if no extraction is available */ void *NumExtract; /* The fields */ Field *fields;} TypeStruct, *TYPESTRUCT;/* Types which are used only for procedure argument types */extern char *wordType;extern char *wordlistType;extern char *valType;extern char *valobjType;/* A list just for compatibility with LastWave 1.xxx.... will be deleted soon */enum { DeleteMsge = 1, GetTypeMsge, GetNameMsge, PrintMsge, LongPrintMsge, ShortPrintMsge, PrintInfoMsge, NumExtractMsge, GetExtractOptionsMsge, GetExtractInfoMsge, GetFieldMsge, SetFieldMsge, ExtractMsge, DisplayMsge, ToStrMsge, SendNameMsge, GetImageMsge, GetSignalMsge, GetValueMsge};extern Field *FindField(Field *fields, char *name);extern void AddRefValue_(VALUE value);extern void RemoveRefValue_(VALUE value);extern void TempValue_(VALUE value);extern char DoesTypeOverwrite(char *type, char *typeOverwrite);extern char *GetBTypeContent(VALUE vc);#define TempValue(value) TempValue_((VALUE) value)#define AddRefValue(value) AddRefValue_((VALUE) value)#define RemoveRefValue(value) RemoveRefValue_((VALUE) value)extern void *GetValue_(VALUE val, void **arg);#define GetValueField(val,arg) GetValue_((VALUE) val,arg)extern char *varType;#define InitValue(vc,ts1) vc->ts = ts1; vc->sendMessage = NULL; vc->nRef = 1#define IsVariable(vc) ((vc)->ts != NULL && *((vc)->ts->type) == varType)#define ValueOf(value) (!(IsVariable(value)) ? (value) : *GetVariablePContent((VARIABLE) (value),NO))#define GetTypeValue(vc) \ (((vc)->ts == NULL ? ((*((vc)->sendMessage))(vc,GetTypeMsge,NULL)) : \ ((vc)->ts->GetType != NULL ? (*((vc)->ts->GetType))((VALUE) vc) : *((vc)->ts->type))))#define GetTrueTypeValue(vc) \ (((vc)->ts == NULL ? GetTypeValue(vc) : *((vc)->ts->type)))#define DeleteValue(vc) \ if ((vc)->ts == NULL) (*((vc)->sendMessage))(vc,DeleteMsge,NULL); else ((void * (*)(VALUE)) ((vc)->ts->Delete)) ((VALUE) vc)#define NewValue(ts) ((VALUE (*)(void)) (ts->New))()#define ToStrValue(vc,flagShort) \ ((vc)->ts == NULL ? "" : \ ((char * (*)(struct value *, char)) ((vc)->ts->ToStr)) ((VALUE) vc,flagShort))#define PrintValue(vc) \ if ((vc)->ts == NULL) (*((vc)->sendMessage))(vc,LongPrintMsge,NULL); \ else if ((vc)->ts->Print == NULL) Printf("%s\n",ToStrValue(vc,NO)); \ else (*((void (*)(struct value *)) ((vc)->ts->Print))) ((VALUE) vc) #define PrintInfoValue(vc) \ if ((vc)->ts == NULL) (*((vc)->sendMessage))(vc,PrintInfoMsge,NULL); \ else (*((void (*)(struct value *)) ((vc)->ts->PrintInfo))) ((VALUE) vc)#define NumExtractValue(vc,arg) \ (((vc)->ts == NULL ? ((*((vc)->sendMessage))(vc,NumExtractMsge,arg)) : \ ((vc)->ts->NumExtract == NULL ? NULL : \ (*((void * (*)(struct value *,void **)) ((vc)->ts->NumExtract))) ((VALUE) (vc),(void **) (arg)))))#define NumExtractTS(ts,arg) \ (*((void * (*)(VALUE,void **)) (ts)->NumExtract))(NULL,arg)#define GetExtractOptionsValue(vc,arg) \ (((vc)->ts == NULL ? ((*((vc)->sendMessage))(vc,GetExtractOptionsMsge,arg)) : \ (FindField((vc)->ts->fields,arg[0]) == NULL ? NULL : \ (FindField((vc)->ts->fields,arg[0])->ExtractOptions == NULL ? NULL : \ ((void * (*)(struct value *, void **)) (FindField((vc)->ts->fields,arg[0]))->ExtractOptions)((VALUE) vc,arg)))))#define GetExtractInfoValue(vc,arg) \ (((vc)->ts == NULL ? ((*((vc)->sendMessage))(vc,GetExtractInfoMsge,arg)) : \ (FindField((vc)->ts->fields,arg[0]) == NULL ? NULL : \ ((void * (*)(struct value *, void **)) (FindField((vc)->ts->fields,arg[0]))->ExtractInfo)((VALUE) vc,arg))))#define GetFieldValue(field,val,arg) (*((void * (*)(VALUE,void **)) (field).Get))(val,arg)#define SetFieldValue(field,val,arg) (*((void * (*)(VALUE,void **)) (field).Set))(val,arg)#define ExtractOptionFieldValue(field,val,arg) (*((void * (*)(VALUE,void **)) (field).ExtractOptions))(val,arg)#define ExtractInfoFieldValue(field,val,arg) (*((void * (*)(VALUE,void **)) (field).ExtractInfo))(val,arg)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -