Changeset 1270 for trunk


Ignore:
Timestamp:
Jan 11, 2009, 10:20:06 PM (16 years ago)
Author:
dkearney
Message:

rappture object updates, stuff i'm playing around with. the code is not functional but it compiles, and i dont want to loose this state as i continue to play. the configure scripts and makefiles should still be working properly.

Location:
trunk
Files:
10 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure

    r1262 r1270  
    1495014950
    1495114951
    14952 ac_config_files="$ac_config_files Makefile packages/Makefile src/Makefile src/core/Makefile src/core2/Makefile src/objects/Makefile gui/Makefile gui/apps/Makefile gui/apps/about gui/apps/rappture gui/apps/rappture-csh.env gui/apps/rappture.env gui/apps/rerun gui/apps/simsim gui/apps/xmldiff gui/pkgIndex.tcl gui/scripts/Makefile lang/Makefile lang/perl/Makefile lang/perl/Makefile.PL lang/python/Makefile lang/python/setup.py lang/matlab/Makefile lang/octave/Makefile lang/octave/RpOctaveInterface.h lang/ruby/Makefile lang/ruby/build.rb lang/tcl/Makefile lang/tcl/pkgIndex.tcl lang/tcl/src/Makefile lang/tcl/scripts/Makefile lang/tcl/tests/Makefile lib/Makefile examples/3D/Makefile examples/Makefile examples/app-fermi/2.0/Makefile examples/app-fermi/Makefile examples/app-fermi/cee/Makefile examples/app-fermi/fortran/Makefile examples/app-fermi/matlab/Makefile examples/app-fermi/matlab/compiled/Makefile examples/app-fermi/matlab/uncompiled/Makefile examples/app-fermi/octave/Makefile examples/app-fermi/perl/Makefile examples/app-fermi/python/Makefile examples/app-fermi/ruby/Makefile examples/app-fermi/tcl/Makefile examples/app-fermi/wrapper/Makefile examples/app-fermi/wrapper/cee/Makefile examples/app-fermi/wrapper/python/Makefile examples/app-fermi/wrapper/tcl/Makefile examples/c-example/Makefile examples/canvas/Makefile examples/demo.bash examples/graph/Makefile examples/objects/Makefile examples/objects/dxWriter/Makefile examples/objects/floatBuffer/Makefile examples/zoo/Makefile examples/zoo/binary/Makefile examples/zoo/boolean/Makefile examples/zoo/choice/Makefile examples/zoo/cloud/Makefile examples/zoo/cloud/matlab/Makefile examples/zoo/curve/Makefile examples/zoo/enable/Makefile examples/zoo/field/Makefile examples/zoo/group/Makefile examples/zoo/image/Makefile examples/zoo/image/docs/Makefile examples/zoo/image/examples/Makefile examples/zoo/integer/Makefile examples/zoo/integer2/Makefile examples/zoo/loader/Makefile examples/zoo/loader/examples/Makefile examples/zoo/loadrun/Makefile examples/zoo/log/Makefile examples/zoo/note/Makefile examples/zoo/note/docs/Makefile examples/zoo/number/Makefile examples/zoo/number2/Makefile examples/zoo/phase/Makefile examples/zoo/sequence/Makefile examples/zoo/sequence/examples/Makefile examples/zoo/string/Makefile examples/zoo/structure/Makefile examples/zoo/structure/examples/Makefile examples/zoo/table/Makefile examples/zoo/unirect2d/Makefile test/Makefile test/src/Makefile"
     14952ac_config_files="$ac_config_files Makefile packages/Makefile src/Makefile src/core/Makefile src/core2/Makefile src/objects/Makefile src/objects/RpHash.h gui/Makefile gui/apps/Makefile gui/apps/about gui/apps/rappture gui/apps/rappture-csh.env gui/apps/rappture.env gui/apps/rerun gui/apps/simsim gui/apps/xmldiff gui/pkgIndex.tcl gui/scripts/Makefile lang/Makefile lang/perl/Makefile lang/perl/Makefile.PL lang/python/Makefile lang/python/setup.py lang/matlab/Makefile lang/octave/Makefile lang/octave/RpOctaveInterface.h lang/ruby/Makefile lang/ruby/build.rb lang/tcl/Makefile lang/tcl/pkgIndex.tcl lang/tcl/src/Makefile lang/tcl/scripts/Makefile lang/tcl/tests/Makefile lib/Makefile examples/3D/Makefile examples/Makefile examples/app-fermi/2.0/Makefile examples/app-fermi/Makefile examples/app-fermi/cee/Makefile examples/app-fermi/fortran/Makefile examples/app-fermi/matlab/Makefile examples/app-fermi/matlab/compiled/Makefile examples/app-fermi/matlab/uncompiled/Makefile examples/app-fermi/octave/Makefile examples/app-fermi/perl/Makefile examples/app-fermi/python/Makefile examples/app-fermi/ruby/Makefile examples/app-fermi/tcl/Makefile examples/app-fermi/wrapper/Makefile examples/app-fermi/wrapper/cee/Makefile examples/app-fermi/wrapper/python/Makefile examples/app-fermi/wrapper/tcl/Makefile examples/c-example/Makefile examples/canvas/Makefile examples/demo.bash examples/graph/Makefile examples/objects/Makefile examples/objects/dxWriter/Makefile examples/objects/floatBuffer/Makefile examples/zoo/Makefile examples/zoo/binary/Makefile examples/zoo/boolean/Makefile examples/zoo/choice/Makefile examples/zoo/cloud/Makefile examples/zoo/cloud/matlab/Makefile examples/zoo/curve/Makefile examples/zoo/enable/Makefile examples/zoo/field/Makefile examples/zoo/group/Makefile examples/zoo/image/Makefile examples/zoo/image/docs/Makefile examples/zoo/image/examples/Makefile examples/zoo/integer/Makefile examples/zoo/integer2/Makefile examples/zoo/loader/Makefile examples/zoo/loader/examples/Makefile examples/zoo/loadrun/Makefile examples/zoo/log/Makefile examples/zoo/note/Makefile examples/zoo/note/docs/Makefile examples/zoo/number/Makefile examples/zoo/number2/Makefile examples/zoo/phase/Makefile examples/zoo/sequence/Makefile examples/zoo/sequence/examples/Makefile examples/zoo/string/Makefile examples/zoo/structure/Makefile examples/zoo/structure/examples/Makefile examples/zoo/table/Makefile examples/zoo/unirect2d/Makefile test/Makefile test/src/Makefile"
    1495314953
    1495414954cat >confcache <<\_ACEOF
     
    1552715527    "src/core2/Makefile") CONFIG_FILES="$CONFIG_FILES src/core2/Makefile" ;;
    1552815528    "src/objects/Makefile") CONFIG_FILES="$CONFIG_FILES src/objects/Makefile" ;;
     15529    "src/objects/RpHash.h") CONFIG_FILES="$CONFIG_FILES src/objects/RpHash.h" ;;
    1552915530    "gui/Makefile") CONFIG_FILES="$CONFIG_FILES gui/Makefile" ;;
    1553015531    "gui/apps/Makefile") CONFIG_FILES="$CONFIG_FILES gui/apps/Makefile" ;;
  • trunk/configure.in

    r1262 r1270  
    1 AC_INIT([Rappture], [1.1], [rappture@nanohub.org])
     1AC_INIT([Rappture],[1.1],[rappture@nanohub.org])
     2dnl AC_CONFIG_HEADER(src/core/RpConfig.h)
    23AC_CONFIG_AUX_DIR(cf)
    34
     
    3536AC_PROG_F77([g77 gfortran f77 fort77 f90 xlf xlf90 fl32])
    3637
    37 AC_LANG_C
     38AC_LANG([C])
    3839
    3940AC_HEADER_STDC
    4041AC_CHECK_FUNC(atol,,AC_MSG_ERROR(oops! no atol ?!?))
    4142
    42 AC_LANG_CPLUSPLUS
     43AC_LANG([C++])
    4344
    4445AC_CHECK_LIB(m, main,,AC_MSG_ERROR(librappture requires libm))
     
    9495done
    9596if test "x${make_command}" = "x" ; then
    96   AC_ERROR([Requires GNU make. You can specify a version with \$MAKE])
     97  AC_MSG_ERROR([Requires GNU make. You can specify a version with \$MAKE])
    9798fi
    9899AC_SUBST(MAKE, ${make_command})
     
    483484
    484485dnl read Makefile.in and write Makefile
    485 AC_OUTPUT( [
     486AC_CONFIG_FILES([
    486487    Makefile
    487488    packages/Makefile
     
    490491    src/core2/Makefile
    491492    src/objects/Makefile
     493    src/objects/RpHash.h
    492494    gui/Makefile
    493495    gui/apps/Makefile
     
    576578    test/src/Makefile
    577579])
     580AC_OUTPUT
  • trunk/src/core/Makefile.in

    r1086 r1270  
    11
    22bindir          = @bindir@
    3 datadir         = @datadir@
    4 datarootdir     = @datarootdir@
     3datadir         = @datadir@
     4datarootdir     = @datarootdir@
    55exec_prefix     = @exec_prefix@
    66includedir      = @includedir@
     
    88mandir          = @mandir@
    99prefix          = @prefix@
    10 srcdir          = @srcdir@
    11 incdir          = $(prefix)/include
     10srcdir          = @srcdir@
     11incdir          = $(prefix)/include
    1212
    13 INSTALL         = @INSTALL@
    14 MKDIR_P         = @MKDIR_P@
     13INSTALL         = @INSTALL@
     14MKDIR_P         = @MKDIR_P@
    1515
    1616CXX             = @CXX@
     
    1919# We need to link with g++ on MacOS 10.4
    2020CC              = $(CXX)
    21 CCC             = @CC@
     21CCC             = @CC@
    2222CFLAGS_DEBUG    = @CFLAGS_DEBUG@ -Wall
    2323CFLAGS_OPTIMIZE = @CFLAGS_OPTIMIZE@
     
    3131CFLAGS          = @CFLAGS@
    3232
    33 CC_SWITCHES     = $(CFLAGS) $(CFLAGS_DEBUG) $(INCLUDES) $(DEFINES)
    34 CXX_SWITCHES    = $(CFLAGS) $(CFLAGS_DEBUG) $(INCLUDES) $(DEFINES)
     33CC_SWITCHES     = $(CFLAGS) $(CFLAGS_DEBUG) $(INCLUDES) $(DEFINES)
     34CXX_SWITCHES    = $(CFLAGS) $(CFLAGS_DEBUG) $(INCLUDES) $(DEFINES)
    3535
    36 INCLUDES        = -I$(srcdir) \
    37                   -I$(includedir)
     36INCLUDES        = \
     37                -I. \
     38                -I$(srcdir) \
     39                -I$(includedir)
    3840
    39 RANLIB          = @RANLIB@
    40 AR              = ar
    41 VPATH           = $(srcdir):$(srcdir)/scew:$(srcdir)/b64
    42 RM              = rm -f
     41RANLIB          = @RANLIB@
     42AR              = ar
     43VPATH           = $(srcdir):$(srcdir)/scew:$(srcdir)/b64
     44RM              = rm -f
    4345
    4446CDEBUGFLAGS     = -g -Wall
    4547
    46 LIBS            = -lexpat -lz -lm -lstdc++
     48LIBS            = -lexpat -lz -lm -lstdc++
    4749
    4850HEADERS = \
     
    7678                RpUtilsFInterface.h \
    7779                RpUtilsFStubs.h \
    78                 rappture.h 
     80                rappture.h
    7981
    8082SCEW_HEADERS    = \
     
    9496                xprint.h \
    9597                xtree.h \
    96                 writer.h \
    97                 xerror.h
     98                writer.h \
     99                xerror.h
    98100
    99101# Build the scew and b64 libraries directly into Rappture for now. 
     
    116118                xhandler.o \
    117119                xparser.o \
    118                 xprint.o 
     120                xprint.o
    119121
    120122OBJS =          \
     
    144146                $(B64_OBJS)
    145147
    146 name            = rappture
    147 libname         = lib$(name)
    148 lib             = $(libname).a
    149 shared_lib      = $(libname)$(SHLIB_SUFFIX)
     148name        = rappture
     149libname     = lib$(name)
     150lib         = $(libname).a
     151shared_lib  = $(libname)$(SHLIB_SUFFIX)
    150152
    151153all: $(lib) $(shared_lib)
  • trunk/src/objects/Makefile.in

    r1018 r1270  
    1414
    1515CXX             = @CXX@
    16 CC              = @CXX@
     16CC              = $(CXX)
     17CCC             = @CC@
    1718CFLAGS_DEBUG    = @CFLAGS_DEBUG@
    1819CFLAGS_OPTIMIZE = @CFLAGS_OPTIMIZE@
     
    2930
    3031INCLUDES        = \
     32                -I. \
     33                -I../core \
    3134                -I$(srcdir) \
    3235                -I$(srcdir)/../core \
     
    4851
    4952HEADERS = \
    50                 RpBoolean.h \
     53                RpChain.h \
     54                RpInt.h \
     55                RpHash.h \
     56                RpHashHelper.h \
     57                RpNumber.h \
     58                RpPool.h \
     59                RpVariable.h
     60
     61#               RpBoolean.h \
    5162                RpAbout.h \
    5263                RpNumber.h \
     
    5768
    5869OBJS = \
    59                 RpAbout.o \
     70                RpChain.o \
     71                RpHash.o \
     72                RpHashHelper.o \
     73                RpNumber.o \
     74                RpPool.o \
     75                RpVariable.o
     76
     77#               RpAbout.o \
    6078                RpBoolean.o \
    6179                RpChoice.o \
     
    93111        $(CXX) $(CC_SWITCHES) -c $?
    94112.c.o:
    95         $(CC) $(CC_SWITCHES) -c $?
     113        $(CCC) $(CC_SWITCHES) -c $?
    96114
    97115clean:
  • trunk/src/objects/RpNumber.cc

    r1018 r1270  
    55 * ======================================================================
    66 *  AUTHOR:  Derrick Kearney, Purdue University
    7  *  Copyright (c) 2004-2005  Purdue Research Foundation
     7 *  Copyright (c) 2005-2009  Purdue Research Foundation
    88 *
    99 *  See the file "license.terms" for information on usage and
     
    1212 */
    1313
     14#include <cstring>
     15#include <stdlib.h>
    1416#include "RpNumber.h"
    1517
    16 /**********************************************************************/
    17 // METHOD: setDefaultValue()
    18 /// set the default value of a RpNumber object.
    19 /**
    20  */
     18#ifndef _RpUNITS_H
     19    #include "RpUnits.h"
     20#endif
    2121
    22 RpNumber&
    23 RpNumber::setDefaultValue(double newDefaultVal) {
     22RpNumber::RpNumber (
     23            const char *path,
     24            const char *unit,
     25            double val
     26        )
     27    :   RpVariable  (),
     28        _default    (val),
     29        _current    (val),
     30        _min        (0.0),
     31        _max        (0.0),
     32        _minmaxSet  (0.0)
     33{
     34    const RpUnits *u = NULL;
    2435
    25     double* def = NULL;
     36    property("path",(const void *)path);
    2637
    27     def = (double*) RpVariable::getDefaultValue();
     38    u = RpUnits::find(std::string(unit));
     39    if (!u) {
     40        u = RpUnits::define(unit,NULL);
     41    }
     42    property("units",(const void *)unit);
    2843
    29     if (!def) {
    30         RpVariable::setDefaultValue(new double (newDefaultVal));
     44    property("default",(const void *)&_default);
     45    property("current",(const void *)&_current);
     46    property("min",(const void *)&_min);
     47    property("max",(const void *)&_max);
     48}
     49
     50RpNumber::RpNumber (
     51            const char *path,
     52            const char *unit,
     53            double val,
     54            double min,
     55            double max,
     56            const char *label,
     57            const char *desc
     58        )
     59    :   RpVariable  (),
     60        _default    (val),
     61        _current    (val),
     62        _min         (min),
     63        _max         (max),
     64        _minmaxSet   (0)
     65{
     66    const RpUnits *u = NULL;
     67
     68    property("path",(const void *)path);
     69
     70    u = RpUnits::find(std::string(unit));
     71    if (! u) {
     72        u = RpUnits::define(unit,NULL);
     73    }
     74    property("units",(const void *)unit);
     75
     76    if ((min == 0) && (max == 0)) {
     77        _minmaxSet = 0;
    3178    }
    3279    else {
    33         *def = newDefaultVal;
     80
     81        if (min > val) {
     82            _min = val;
     83        }
     84
     85        if (max < val) {
     86            _max = val;
     87        }
    3488    }
    3589
    36     return *this;
     90    property("default",(const void *)&_default);
     91    property("current",(const void *)&_current);
     92    property("min",(const void *)&_min);
     93    property("max",(const void *)&_max);
     94}
     95
     96// copy constructor
     97RpNumber::RpNumber ( const RpNumber& o )
     98    :   RpVariable(o),
     99        _default    (o._default),
     100        _current    (o._current),
     101        _min        (o._min),
     102        _max        (o._max),
     103        _minmaxSet  (o._minmaxSet)
     104{}
     105
     106// default destructor
     107RpNumber::~RpNumber ()
     108{
     109    // clean up dynamic memory
     110
    37111}
    38112
    39113/**********************************************************************/
    40 // METHOD: setCurrentValue()
    41 /// Set the current value of a RpNumber object.
     114// METHOD: units()
     115/// get / set the units of this number
    42116/**
     117 * get / set the units property of this object
    43118 */
    44119
    45 RpNumber&
    46 RpNumber::setCurrentValue(double newCurrentVal) {
    47 
    48     double* cur = (double*) RpVariable::getCurrentValue();
    49     double* def = (double*) RpVariable::getDefaultValue();
    50 
    51     if (cur == def) {
    52         RpVariable::setCurrentValue(new double (newCurrentVal));
    53     }
    54     else {
    55         *cur = newCurrentVal;
    56     }
    57 
    58     return *this;
     120const char *
     121RpNumber::units(
     122    const char *val)
     123{
     124    return (const char *) property("units",val);
    59125}
    60126
    61 
    62 /**********************************************************************/
    63 // METHOD: setMin()
    64 /// Set the min value of a RpNumber object.
    65 /**
    66  */
    67 
    68 RpNumber&
    69 RpNumber::setMin(double newMin) {
    70 
    71     min = newMin;
    72     return *this;
    73 }
    74 
    75 /**********************************************************************/
    76 // METHOD: setMax()
    77 /// set the min value of a RpNumber object
    78 /**
    79  */
    80 
    81 RpNumber&
    82 RpNumber::setMax(double newMax) {
    83 
    84     max = newMax;
    85     return *this;
    86 }
    87 
    88 /**********************************************************************/
    89 // METHOD: getUnits()
    90 /// Report the units of the object.
    91 /**
    92  */
    93 
    94 std::string
    95 RpNumber::getUnits() const {
    96 
    97     return units->getUnitsName();
    98 }
    99 
    100 
    101 /**********************************************************************/
    102 // METHOD: getDefaultValue()
    103 /// Report the default value of the object.
    104 /**
    105  */
    106 
    107 double
    108 RpNumber::getDefaultValue(void* null_val) const {
    109 
    110     return *((double*) RpVariable::getDefaultValue());
    111 }
    112 
    113 /**********************************************************************/
    114 // METHOD: getCurrentValue()
    115 /// Report the current value of the object.
    116 /**
    117  */
    118 
    119 double
    120 RpNumber::getCurrentValue(void* null_val) const {
    121 
    122     return *((double*) RpVariable::getCurrentValue());
    123 }
    124 
    125 /**********************************************************************/
    126 // METHOD: getMin()
    127 /// Report the min of the object.
    128 /**
    129  */
    130 
    131 double
    132 RpNumber::getMin() const {
    133 
    134     return min;
    135 }
    136 
    137 /**********************************************************************/
    138 // METHOD: getMax()
    139 /// report the max of the object.
    140 /**
    141  */
    142 
    143 double
    144 RpNumber::getMax() const {
    145 
    146     return max;
    147 }
    148127
    149128/**********************************************************************/
     
    155134
    156135double
    157 RpNumber::convert(std::string toUnitStr, int storeResult, int* result) {
     136RpNumber::convert(const char *to) {
    158137
    159138    const RpUnits* toUnit = NULL;
    160     double retVal = 0;
    161     int my_result = 0;
     139    const RpUnits* fromUnit = NULL;
     140    double convertedVal = _current;
     141    int err = 0;
    162142
    163     toUnit = RpUnits::find(toUnitStr);
    164 
    165     // set the result to the default value if it exists
    166     if (result) {
    167         *result = my_result;
     143    // make sure all units functions accept char*'s
     144    toUnit = RpUnits::find(std::string(to));
     145    if (!toUnit) {
     146        // should raise error!
     147        // conversion not defined because unit does not exist
     148        return _current;
    168149    }
    169150
    170     if (!toUnit) {
    171         // should raise error!
     151    fromUnit = RpUnits::find(std::string(units(NULL)));
     152    if (!fromUnit) {
     153        // should raise error!
    172154        // conversion not defined because unit does not exist
    173         return retVal;
     155        return _current;
    174156    }
    175157
    176158    // perform the conversion
    177     retVal = convert(toUnit,&my_result);
    178 
    179     // check the result of the conversion and store if necessary
    180     if (my_result) {
    181         if (result) {
    182             *result = my_result;
    183         }
    184 
    185         // check if we should store the value and change units
    186         if (storeResult) {
    187             // no need to deallocate old units,
    188             // because they are stored in static dictionary
    189             units = toUnit;
    190             RpNumber::setCurrentValue(retVal);
    191         }
     159    convertedVal = fromUnit->convert(toUnit,_default, &err);
     160    if (!err) {
     161        _default = convertedVal;
    192162    }
    193163
    194     return retVal;
     164    convertedVal = fromUnit->convert(toUnit,_current, &err);
     165    if (!err) {
     166        _current = convertedVal;
     167    }
     168
     169    if (err) {
     170        convertedVal = _current;
     171    }
     172
     173    return convertedVal;
    195174}
    196 
    197 /**********************************************************************/
    198 // METHOD: convert()
    199 /// Convert the number object to another unit from string.
    200 /**
    201  */
    202 
    203 double
    204 RpNumber::convert(std::string toUnitStr, int* result) {
    205 
    206     const RpUnits* toUnit = NULL;
    207     toUnit = RpUnits::find(toUnitStr);
    208     if (!toUnit) {
    209         // should raise error!
    210         // conversion not defined because unit does not exist
    211         if (result) {
    212             *result = -1;
    213         }
    214         return 0.0;
    215     }
    216     return convert(toUnit, result);
    217 }
    218 
    219 /**********************************************************************/
    220 // METHOD: convert()
    221 /// Convert the number object to another unit from RpUnits object.
    222 /**
    223  */
    224 
    225 double
    226 RpNumber::convert(const RpUnits* toUnit, int *result) {
    227 
    228     return units->convert(toUnit,getCurrentValue(), result);
    229 }
    230 
    231 /**********************************************************************/
    232 // METHOD: put()
    233 /// Store the information of this Rappture Object into the xml
    234 /**
    235  */
    236 //
    237 //RpNumber&
    238 //RpNumber::put() const {
    239 //
    240 //   
    241 //    return *this;
    242 //}
    243 
    244175
    245176// -------------------------------------------------------------------- //
  • trunk/src/objects/RpNumber.h

    r1018 r1270  
    11/*
    22 * ======================================================================
    3  *  Copyright (c) 2004-2005  Purdue Research Foundation
     3 *  AUTHOR:  Derrick Kearney, Purdue University
     4 *  Copyright (c) 2005-2009  Purdue Research Foundation
    45 *
    56 *  See the file "license.terms" for information on usage and
     
    78 * ======================================================================
    89 */
    9 #include <iostream>
    10 #include <string>
    11 #include <sstream>
    12 #include <stdlib.h>
    1310#include <errno.h>
    14 
    15 
    16 // #include "RpLibrary.h"
    1711
    1812#ifndef _RpVARIABLE_H
     
    2014#endif
    2115
    22 #ifndef _RpUNITS_H
    23     #include "RpUnits.h"
    24 #endif
    25 
    26 #ifndef _RpNUMBER_H
     16#ifndef _RpNUMBER_H
    2717#define _RpNUMBER_H
    2818
     
    3121    public:
    3222
    33         // users member fxns
     23        RpNumber (  const char *path,
     24                    const char *unit,
     25                    double val);
    3426
    35         /*
    36         virtual RpNumber& setUnits(std::string newUnits);
    37         */
    38 
    39         virtual RpNumber& setDefaultValue(double newDefaultVal);
    40         virtual RpNumber& setCurrentValue(double newCurrentVal);
    41         virtual RpNumber& setMin(double newMin);
    42         virtual RpNumber& setMax(double newMax);
    43 
    44         std::string getUnits() const;
    45         // changed from "Value" to "Val" because base class makes
    46         // these functions virtual and derived class has a different
    47         // return type. compiler doesnt like this. need to find another
    48         // way around this
    49         //
    50         // if we keep the null_val=NULL will that give us undefined behavior?
    51         //
    52         double getDefaultValue(void* null_val=NULL) const;
    53         double getCurrentValue(void* null_val=NULL) const;
    54         double getMin() const;
    55         double getMax() const;
    56 
    57         double convert( std::string toUnitStr,
    58                         int storeResult,
    59                         int* result = NULL  );
    60         double convert(std::string toUnitStr, int* result = NULL);
    61         double convert(const RpUnits* toUnit, int* result = NULL);
    62 
    63         // place the information from this object into the xml library 'lib'
    64         // virtual RpNumber& put(RpLibrary lib);
    65         RpNumber& put() const;
    66         RpNumber& put(double currentVal);
    67 
    68 
    69 
    70         /*
    71          * user provides a 'path' for where this object lives in xml file
    72          * user calls define with standard hints as described in Number docs
    73          *  'units' - string providing units of the number
    74          *  'defaultVal' - numeric value to be used if user provides no value
    75          *  'min' - (optional) minimum allowed value
    76          *  'max' - (optional) maximum allowed value
    77          *  'label' - (optional) name of the input for a gui field
    78          *  'desc' - (optional) description of the input for the gui
    79          *
    80          *  Notes:
    81          *      if the user sets a min or max value the following applies:
    82          *          if the value of min is greater than the value of default,
    83          *          then min will be set to default
    84          *
    85          *          if the value of max is less than the value of default,
    86          *          then max will be set to default.
    87          *
    88          *
    89          *
    90          */
    91 
    92         /* what about unit-less numbers */
    93         RpNumber (
    94                     std::string path,
    95                     std::string units,
    96                     double defaultVal
    97                 )
    98             :   RpVariable  (path, new double (defaultVal) ),
    99                 // units       (units),
    100                 min         (0),
    101                 max         (0),
    102                 minmaxSet   (0)
    103         {
    104             this->units = RpUnits::find(units);
    105             if (! this->units) {
    106                 this->units = RpUnits::define(units,NULL);
    107             }
    108         }
    109 
    110         RpNumber (
    111                     std::string path,
    112                     std::string units,
    113                     double defaultVal,
     27        RpNumber (  const char *path,
     28                    const char *unit,
     29                    double val,
    11430                    double min,
    11531                    double max,
    116                     std::string label,
    117                     std::string desc
    118                 )
    119             :   RpVariable  (path, new double (defaultVal), label, desc),
    120                 // units       (units),
    121                 min         (min),
    122                 max         (max),
    123                 minmaxSet   (0)
    124         {
     32                    const char *label,
     33                    const char *desc);
    12534
    126             this->units = RpUnits::find(units);
    127             if (! this->units) {
    128                 this->units = RpUnits::define(units,NULL);
    129             }
     35        RpNumber ( const RpNumber& o );
     36        virtual ~RpNumber ();
    13037
    131             if ((min == 0) && (max == 0)) {
    132                 minmaxSet = 0;
    133             }
    134             else {
     38        virtual const double defaultValue    (double val);
     39        virtual const double currentValue    (double val);
     40        virtual const double min             (double val);
     41        virtual const double max             (double val);
     42        virtual const char *units            (const char *val);
     43        // need to add a way to tell user conversion failed
     44        virtual double convert               (const char *to);
    13545
    136                 if (min > defaultVal) {
    137                     this->min = defaultVal;
    138                 }
    139 
    140                 if (max < defaultVal) {
    141                     this->max = defaultVal;
    142                 }
    143             }
    144 
    145         }
    146 
    147         // copy constructor
    148         RpNumber ( const RpNumber& myRpNumber )
    149             :   RpVariable(myRpNumber),
    150                 units       (myRpNumber.units),
    151                 min         (myRpNumber.min),
    152                 max         (myRpNumber.max),
    153                 minmaxSet   (myRpNumber.minmaxSet)
    154         {}
    155 
    156         // default destructor
    157         // virtual ~RpNumber ()
    158         virtual ~RpNumber ()
    159         {
    160             // clean up dynamic memory
    161 
    162         }
    16346    private:
    16447
    165         // std::string units;
    166         const RpUnits* units;
    167         double min;
    168         double max;
     48        double _default;
     49        double _current;
     50        double _min;
     51        double _max;
    16952
    170         // flag to tell if the user specified the min and max values
    171         int minmaxSet;
    172 
     53        // flag tells if user specified min and max values
     54        int _minmaxSet;
    17355};
    17456
  • trunk/src/objects/RpVariable.cc

    r1018 r1270  
    77 * ======================================================================
    88 *  AUTHOR:  Derrick Kearney, Purdue University
    9  *  Copyright (c) 2004-2005  Purdue Research Foundation
     9 *  Copyright (c) 2005-2009  Purdue Research Foundation
    1010 *
    1111 *  See the file "license.terms" for information on usage and
     
    1414 */
    1515
    16  #include "RpVariable.h"
     16#include <cstring>
     17#include <stdlib.h>
     18#include "RpVariable.h"
     19#include "RpHashHelper.h"
    1720
    18 /**********************************************************************/
    19 // METHOD: setPath()
    20 /// Set the path of this object
    21 /**
    22  */
    23 
    24 RpVariable&
    25 RpVariable::setPath(std::string newPath)
     21RpVariable::RpVariable()
    2622{
    27     path = newPath;
    28     return *this;
     23    __init();
    2924}
    3025
    31 /**********************************************************************/
    32 // METHOD: setDefaultValue()
    33 /// Set the default value of this object
    34 /**
    35  */
    36 
    37 RpVariable&
    38 RpVariable::setDefaultValue(void* newDefaultVal)
     26RpVariable::RpVariable(const RpVariable& o)
     27    :
     28        _path (o._path)
    3929{
    40     // who is responsible for freeing the pointer?
    41     defaultVal = newDefaultVal;
    42     return *this;
     30    if (o._h != NULL) {
     31        Rp_HashCopy(_h,o._h,charCpyFxn);
     32    }
    4333}
    4434
    45 /**********************************************************************/
    46 // METHOD: setCurrentValue()
    47 /// Set the current value of this object
    48 /**
    49  */
    50 
    51 RpVariable&
    52 RpVariable::setCurrentValue(void* newCurrentVal)
     35RpVariable::~RpVariable()
    5336{
    54     // who is responsible for freeing the pointer?
    55     currentVal = newCurrentVal;
    56     return *this;
     37    __close();
    5738}
    5839
    59 /**********************************************************************/
    60 // METHOD: setLabel()
    61 /// Set the label of this object
    62 /**
    63  */
    64 
    65 RpVariable&
    66 RpVariable::setLabel(std::string newLabel)
     40const char *
     41RpVariable::label(
     42    const char *val)
    6743{
    68     about.setLabel(newLabel);
    69     return *this;
     44    return (const char *) property("label",val);
    7045}
    7146
    72 /**********************************************************************/
    73 // METHOD: setDesc()
    74 /// Set the desc of this object
    75 /**
    76  */
    77 
    78 RpVariable&
    79 RpVariable::setDesc(std::string newDesc)
     47const char *
     48RpVariable::desc(
     49    const char *val)
    8050{
    81     about.setDesc(newDesc);
    82     return *this;
     51    return (const char *) property("desc",val);
    8352}
    8453
    85 /**********************************************************************/
    86 // METHOD: setHints()
    87 /// Set the hints of this object
    88 /**
    89  */
    90 
    91 RpVariable&
    92 RpVariable::setHints(std::string newHints)
     54const char *
     55RpVariable::hints(
     56    const char *val)
    9357{
    94     about.setHints(newHints);
    95     return *this;
     58    return (const char *) property("hints",val);
    9659}
    9760
    98 /**********************************************************************/
    99 // METHOD: setColor()
    100 /// Set the color of this object
    101 /**
    102  */
    103 
    104 RpVariable&
    105 RpVariable::setColor(std::string newColor)
     61const char *
     62RpVariable::color(
     63    const char *val)
    10664{
    107     about.setColor(newColor);
    108     return *this;
     65    return (const char *) property("color",val);
    10966}
    11067
    111 /**********************************************************************/
    112 // METHOD: setIcon()
    113 /// Set the icon of this object
    114 /**
    115  */
    116 
    117 RpVariable&
    118 RpVariable::setIcon(std::string newIcon)
     68const char *
     69RpVariable::icon(
     70    const char *val)
    11971{
    120     about.setIcon(newIcon);
    121     return *this;
     72    return (const char *) property("icon",val);
    12273}
    12374
    124 
    125 /**********************************************************************/
    126 // METHOD: getPath()
    127 /// Report the path of this object
    128 /**
    129  */
    130 
    131 std::string
    132 RpVariable::getPath() const
     75const char *
     76RpVariable::path(
     77    const char *val)
    13378{
    134     return path;
     79    return (const char *) property("path",val);
    13580}
    13681
    137 /**********************************************************************/
    138 // METHOD: getDefaultValue()
    139 /// Report the default value of the object
    140 /**
    141  */
     82const void *
     83RpVariable::property(
     84    const char *key,
     85    const void *val)
     86{
     87    const void *r = NULL;
     88    if (_h == NULL) {
     89        // hash table does not exist, create it
     90        _h = (Rp_HashTable*) malloc(sizeof(Rp_HashTable));
     91        Rp_InitHashTable(_h,RP_STRING_KEYS);
     92        return NULL;
     93    }
    14294
    143 void*
    144 RpVariable::getDefaultValue() const
    145 {
    146     return defaultVal;
     95    if (val == NULL) {
     96        // get the value
     97        r = Rp_HashSearchNode(_h,key);
     98    } else {
     99        //set the value
     100        Rp_HashRemoveNode(_h,key);
     101        Rp_HashAddNode(_h,key,val);
     102        r = val;
     103    }
     104
     105    return r;
    147106}
    148107
    149 /**********************************************************************/
    150 // METHOD: getCurrentValue()
    151 /// Report the current value of the object
    152 /**
    153  */
    154 
    155 void*
    156 RpVariable::getCurrentValue() const
     108void
     109RpVariable::__init()
    157110{
    158     return currentVal;
     111    _path = NULL;
     112    _h = NULL;
    159113}
    160114
    161 /**********************************************************************/
    162 // METHOD: getLabel()
    163 /// Report the label of the object
    164 /**
    165  */
     115void
     116RpVariable::__close()
     117{
     118    if (_path != NULL) {
     119        free((void *)_path);
     120    }
    166121
    167 std::string
    168 RpVariable::getLabel() const
    169 {
    170     return about.getLabel();
    171 }
     122    if (_h != NULL) {
     123        Rp_DeleteHashTable(_h);
     124    }
    172125
    173 /**********************************************************************/
    174 // METHOD: getDesc()
    175 /// Report the desc of the object
    176 /**
    177  */
    178 
    179 std::string
    180 RpVariable::getDesc() const
    181 {
    182     return about.getDesc();
    183 }
    184 
    185 /**********************************************************************/
    186 // METHOD: getHints()
    187 /// Report the hints of this object
    188 /**
    189  */
    190 
    191 std::string
    192 RpVariable::getHints() const
    193 {
    194     return about.getHints();
    195 }
    196 
    197 /**********************************************************************/
    198 // METHOD: getColor()
    199 /// Report the color of this object
    200 /**
    201  */
    202 
    203 std::string
    204 RpVariable::getColor() const
    205 {
    206     return about.getColor();
    207 }
    208 
    209 /**********************************************************************/
    210 // METHOD: getIcon()
    211 /// Report the icon of this object
    212 /**
    213  */
    214 
    215 std::string
    216 RpVariable::getIcon() const
    217 {
    218     return about.getIcon();
     126    __init();
    219127}
    220128
  • trunk/src/objects/RpVariable.h

    r1018 r1270  
    11/*
    22 * ======================================================================
    3  *  Copyright (c) 2004-2005  Purdue Research Foundation
     3 *  AUTHOR:  Derrick S. Kearney, Purdue University
     4 *  Copyright (c) 2005-2009  Purdue Research Foundation
    45 *
    56 *  See the file "license.terms" for information on usage and
     
    78 * ======================================================================
    89 */
    9 #include <iostream>
    10 #include <string>
    11 #include <sstream>
    12 #include <stdlib.h>
    13 #include <errno.h>
    1410
     11#ifndef _RpVARIABLE_H
     12#define _RpVARIABLE_H
    1513
    16 // #include "RpLibrary.h"
    17 
    18 #ifndef _RpABOUT_H
    19     #include "RpAbout.h"
    20 #endif
    21 
    22 #ifndef _RpVARIABLE_H
    23 #define _RpVARIABLE_H
     14#include "RpInt.h"
     15#include "RpHash.h"
    2416
    2517class RpVariable
    2618{
    2719    public:
    28        
    29         // users member fxns
     20        RpVariable ();
     21        RpVariable (const RpVariable& o);
     22        virtual ~RpVariable();
    3023
    31         virtual RpVariable& setPath         (std::string newPath);
    32         virtual RpVariable& setDefaultValue (void* newDefaultVal);
    33         virtual RpVariable& setCurrentValue (void* newCurrentVal);
    34         virtual RpVariable& setLabel        (std::string newLabel);
    35         virtual RpVariable& setDesc         (std::string newDesc);
    36         virtual RpVariable& setHints        (std::string newHints);
    37         virtual RpVariable& setColor        (std::string newColor);
    38         virtual RpVariable& setIcon         (std::string newIcon);
    39 
    40         virtual std::string getPath         () const;
    41         /* maybe we dont need 2 get functions? */
    42         virtual void* getDefaultValue       () const;
    43         virtual void* getCurrentValue       () const;
    44         virtual std::string getLabel        () const;
    45         virtual std::string getDesc         () const;
    46         virtual std::string getHints        () const;
    47         virtual std::string getColor        () const;
    48         virtual std::string getIcon         () const;
    49 
    50         // place the information from this object into the xml library 'lib'
    51         // virtual RpNumber& put(RpLibrary lib);
    52         // virtual RpVariable& put() const;
    53 
    54         // we need a copy of defaultVal in currentVal, not the same pointer.
    55         // need to fix this.
    56        
    57         RpVariable (
    58                     std::string path,
    59                     void* defaultVal
    60                 )
    61             :   about       (RpAbout()),
    62                 path        (path),
    63                 defaultVal  (defaultVal),
    64                 currentVal  (defaultVal)
    65         {
    66             // about's default no-arg const is called
    67         };
    68 
    69         RpVariable (
    70                     std::string path,
    71                     void* defaultVal,
    72                     std::string label,
    73                     std::string desc
    74                 )
    75             :   about       (RpAbout(label,desc)),
    76                 path        (path),
    77                 defaultVal  (defaultVal),
    78                 currentVal  (defaultVal)
    79         {}
    80        
    81         // copy constructor
    82         RpVariable ( const RpVariable& myRpVariable )
    83                 // will the RpAbout copy constructor be called here?
    84             :   about       (RpAbout(myRpVariable.about)),
    85                 path        (myRpVariable.path),
    86                 defaultVal  (myRpVariable.defaultVal),
    87                 currentVal  (myRpVariable.currentVal)
    88         {}
    89 
    90         // default destructor
    91         virtual ~RpVariable ()
    92         {
    93             // clean up dynamic memory
    94         }
     24        virtual const char *label           (const char *val);
     25        virtual const char *desc            (const char *val);
     26        virtual const char *hints           (const char *val);
     27        virtual const char *color           (const char *val);
     28        virtual const char *icon            (const char *val);
     29        virtual const char *path            (const char *val);
     30        virtual const void *property        (const char *key, const void *val);
    9531
    9632    private:
    9733
    98         RpAbout about;
    99         std::string path;
    100         void* defaultVal;
    101         void* currentVal;
     34        /// path of the object in the xml tree and key in hash tables
     35        const char *_path;
    10236
     37        /// hash table holding other object properties
     38        Rp_HashTable *_h;
    10339
     40        /// initialize the object, set the data members to 0 or null
     41        void __init();
     42
     43        /// close out the object, freeing its memory
     44        void __close();
    10445};
    10546
Note: See TracChangeset for help on using the changeset viewer.