webengine/wmlengine/src/script/include/scr_val.h
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 1999 - 2001 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19  /*
       
    20     $Workfile: scr_val.h $
       
    21 
       
    22     Purpose:
       
    23 
       
    24   representing typed values in 4 bytes
       
    25  */
       
    26 
       
    27 #ifndef SCR_VAL_H
       
    28 #define SCR_VAL_H
       
    29 
       
    30 #include "scr_defs.h"
       
    31 #include "scr_str.h"
       
    32 
       
    33 typedef enum 
       
    34 {
       
    35     VAL_TYPE_INT,
       
    36     VAL_TYPE_FLOAT,
       
    37     VAL_TYPE_STR,
       
    38     VAL_TYPE_BOOL,
       
    39     VAL_TYPE_INVALID,
       
    40     VAL_TYPE_UNINITIALIZED
       
    41 } SCR_VAL_TYPE;
       
    42 
       
    43 /* Note: use "volatile" keyword to suppress compiler optimizer bug */
       
    44 /*       which changes store/load operation into a data-type cast */
       
    45 typedef struct 
       
    46 {
       
    47    volatile union {
       
    48       NW_Int32    i;
       
    49       NW_Float32  f;
       
    50       str_t       s;
       
    51       NW_Bool     b;
       
    52    }value;
       
    53 
       
    54    SCR_VAL_TYPE type;
       
    55 } val_t;
       
    56 
       
    57 NW_Ucs2* GetUcs2Val(void);
       
    58 NW_Ucs2* GetUcs2Val_notrim(void);
       
    59 NW_Bool GetIntVal(NW_Int32 *value);
       
    60 NW_Bool GetBoolVal(NW_Bool *value);
       
    61 NW_Opaque_t* GetOpaqueVal(void);
       
    62 
       
    63 val_t new_int_val(NW_Int32  i);
       
    64 val_t new_float_val(NW_Float32 f);
       
    65 val_t new_bool_val(NW_Bool b);
       
    66 val_t new_empty_str_val(void);
       
    67 val_t new_str_val(str_t s);
       
    68 val_t new_str_val_and_free(str_t *sptr);
       
    69 val_t new_invalid_val(void);
       
    70 val_t uninitialize_val(void);
       
    71 val_t dup_val(val_t);
       
    72 
       
    73 NW_Bool val2float(val_t v, NW_Float32 *f);
       
    74 NW_Bool val2int(val_t v, NW_Int32  *res);
       
    75 NW_Bool val2bool(val_t v, NW_Bool *res);
       
    76 NW_Bool val2str(val_t v, str_t *str);
       
    77 NW_Bool val2str_and_free(val_t *vptr, str_t *str);
       
    78 
       
    79 NW_Ucs2 *val2ucs2(val_t v);
       
    80 NW_Ucs2 *val2ucs2_trim(val_t v);
       
    81 
       
    82 SCR_VAL_TYPE ScriptVarType(val_t v);
       
    83 
       
    84 void free_val(val_t v);
       
    85 
       
    86  
       
    87 #define IS_INT(v) ((v).type == VAL_TYPE_INT)
       
    88 
       
    89 #define IS_FLOAT(v) ((v).type == VAL_TYPE_FLOAT)
       
    90 
       
    91 #define IS_BOOL(v) ((v).type == VAL_TYPE_BOOL)
       
    92 
       
    93 #define IS_STR(v) ((v).type == VAL_TYPE_STR)
       
    94 
       
    95 #define IS_INVALID(v) ((v).type == VAL_TYPE_INVALID)
       
    96 
       
    97 #endif  /*SCR_VAL_H*/
       
    98