Changeset 114 for trunk/src


Ignore:
Timestamp:
Oct 20, 2005, 8:47:25 PM (19 years ago)
Author:
dkearney
Message:

updates to RpUnits to reduce memory leaks
created copy constructors, destructors, and copy assignment operators
for Units classes. removed conv as a data member and removed several
constructors. removed prev & next pointers from conversion class.
this removes linked list feature from conversion class which was not
being used. this update does not fix python's problem with performing
conversion between RpUnits objects or the allow for the recognition of
/cm3 as an object related to cm3.

also removed some outdated files rappture_interface.h, rappture_interface.c.
RpDict?.cc has been moved into RpDict?.h in previous checkins to reduce
dependencies on include files.

Location:
trunk/src
Files:
2 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpUnits.cc

    r104 r114  
    433433                  const RpUnits* to,
    434434                  double (*convForwFxnPtr)(double),
    435                   double (*convBackFxnPtr)(double)) {
    436 
    437     RpUnits* conv = new RpUnits(    from,
    438                                     to,
    439                                     convForwFxnPtr,
    440                                     convBackFxnPtr,
    441                                     NULL,
    442                                     NULL);
    443 
    444     return conv;
     435                  double (*convBackFxnPtr)(double)  ) {
     436
     437    // this is kinda the wrong way to get the job done...
     438    // how do we only create 1 conversion object and share it between atleast two RpUnits
     439    // objs so that when the RpUnits objs are deleted, we are not trying to delete already
     440    // deleted memory.
     441    // so for the sake of safety we get the following few lines of code.
     442
     443    conversion* conv1 = NULL;
     444    conversion* conv2 = NULL;
     445
     446    conv1 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr);
     447    conv2 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr);
     448
     449    from->connectConversion(conv1);
     450    to->connectConversion(conv2);
     451
     452    return NULL;
    445453}
    446454
     
    451459                  double (*convBackFxnPtr)(double,double)) {
    452460
    453     RpUnits* conv = new RpUnits(    from,
    454                                     to,
    455                                     convForwFxnPtr,
    456                                     convBackFxnPtr,
    457                                     NULL,
    458                                     NULL);
    459 
    460     return conv;
     461    // this is kinda the wrong way to get the job done...
     462    // how do we only create 1 conversion object and share it between atleast two RpUnits
     463    // objs so that when the RpUnits objs are deleted, we are not trying to delete already
     464    // deleted memory.
     465    // so for the sake of safety we get the following few lines of code.
     466
     467    conversion* conv1 = NULL;
     468    conversion* conv2 = NULL;
     469
     470    conv1 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr);
     471    conv2 = new conversion (from,to,convForwFxnPtr,convBackFxnPtr);
     472
     473    from->connectConversion(conv1);
     474    to->connectConversion(conv2);
     475
     476    return NULL;
    461477}
    462478
     
    469485                  void* convBackData) {
    470486
    471     RpUnits* conv = new RpUnits(    from,
    472                                     to,
    473                                     convForwFxnPtr,
    474                                     convForwData,
    475                                     convBackFxnPtr,
    476                                     convBackData,
    477                                     NULL,
    478                                     NULL);
    479 
    480     return conv;
     487    // this is kinda the wrong way to get the job done...
     488    // how do we only create 1 conversion object and share it between atleast two RpUnits
     489    // objs so that when the RpUnits objs are deleted, we are not trying to delete already
     490    // deleted memory.
     491    // so for the sake of safety we get the following few lines of code.
     492
     493    conversion* conv1 = NULL;
     494    conversion* conv2 = NULL;
     495
     496    conv1 = new conversion (from,to,convForwFxnPtr,convForwData,convBackFxnPtr,convBackData);
     497    conv2 = new conversion (from,to,convForwFxnPtr,convForwData,convBackFxnPtr,convBackData);
     498
     499    from->connectConversion(conv1);
     500    to->connectConversion(conv2);
     501
     502    return NULL;
    481503}
    482504
     
    630652    const RpUnits* basis = getBasis();
    631653    double retVal = *value;
    632     int convResult = 0;
     654    int convResult = 1;
    633655
    634656    if (basis == NULL) {
     
    644666    }
    645667
    646     if ( (convResult == 1) ) {
     668    if ( (convResult == 0) ) {
    647669        *value = retVal;
    648670    }
     
    12061228    // check if the list was created previously. if not, start the list
    12071229    if (head == 0) {
    1208         head = new unit(units,exponent,basis,NULL);
     1230        head = new unit(units,exponent,basis,NULL,NULL);
    12091231        return;
    12101232    }
    12111233
    12121234    // now add a new node at the beginning of the list:
    1213     p = new unit(units,exponent,basis,head);
     1235    p = new unit(units,exponent,basis,NULL,head);
    12141236    head->prev = p;
    12151237    head = p;
     
    13431365
    13441366
    1345 void 
    1346 RpUnits::connectConversion(const RpUnits* myRpUnit) {
    1347 
    1348     convEntry* p = myRpUnit->convList;
     1367void
     1368RpUnits::connectConversion(conversion* conv) const {
     1369
     1370    convEntry* p = convList;
    13491371
    13501372    if (p == NULL) {
    1351         myRpUnit->convList = new convEntry (this->conv,NULL,NULL);
     1373        convList = new convEntry (conv,NULL,NULL);
    13521374    }
    13531375    else {
     
    13561378        }
    13571379
    1358         p->next = new convEntry (this->conv,p,NULL);
     1380        p->next = new convEntry (conv,p,NULL);
    13591381    }
    13601382
     
    13631385// return codes: 0 success, anything else is error
    13641386int
    1365 RpUnits::addPresets (std::string group) {
     1387RpUnits::addPresets (const std::string group) {
    13661388    int retVal = -1;
    13671389    if (group.compare("all") == 0) {
Note: See TracChangeset for help on using the changeset viewer.