Changeset 1133 for trunk/yat/classifier


Ignore:
Timestamp:
Feb 23, 2008, 9:40:35 PM (13 years ago)
Author:
Peter
Message:

using SmartPtr? in KernelLookup? rather than doing the ref count myself

Location:
trunk/yat/classifier
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/KernelLookup.cc

    r1132 r1133  
    3838
    3939  KernelLookup::KernelLookup(const Kernel& kernel, const bool own)
    40     : kernel_(&kernel)
    41   {
    42     if (own)
    43       ref_count_ = new u_int(1);
    44     else
    45       ref_count_ = NULL;
     40    : kernel_(utility::SmartPtr<const Kernel>(&kernel, own))
     41  {
    4642    column_index_.reserve(kernel.size());
    4743    for(size_t i=0; i<kernel.size(); i++)
     
    5551                             const std::vector<size_t>& column,
    5652                             const bool owner)
    57     : column_index_(column), kernel_(&kernel), ref_count_(NULL),
     53    : column_index_(column),
     54      kernel_(utility::SmartPtr<const Kernel>(&kernel, owner)),
    5855      row_index_(row)
    5956  {
     
    8481      column_index_.push_back(other.column_index_[column[i]]);
    8582    }
    86     ref_count_=other.ref_count_;
    87     if (ref_count_)
    88       ++(*ref_count_);
    8983  }
    9084 
     
    10195           *(max_element(column_index_.begin(), column_index_.end()))<
    10296           kernel_->size());
    103     ref_count_=other.ref_count_;
    104     if (ref_count_)
    105       ++(*ref_count_);
    10697  }
    10798 
     
    138129           *(max_element(column_index_.begin(), column_index_.end()))<
    139130           kernel_->size());
    140     ref_count_=other.ref_count_;
    141     if (ref_count_)
    142       ++(*ref_count_);
    143131  }
    144132 
     
    146134  KernelLookup::~KernelLookup(void)
    147135  {
    148     if (ref_count_)
    149       if (!--(*ref_count_))
    150         delete kernel_;
    151136  }
    152137
  • trunk/yat/classifier/KernelLookup.h

    r1132 r1133  
    2828
    2929#include "Kernel.h"
    30 #include "DataLookup2D.h"
    31 #include "MatrixLookup.h"
    3230#include "yat/utility/Container2DIterator.h"
    3331#include "yat/utility/iterator_traits.h"
     32#include "yat/utility/SmartPtr.h"
    3433#include "yat/utility/StrideIterator.h"
    35 
    3634
    3735#include <vector>
     
    4139namespace classifier {
    4240
     41  class DataLookup2D;
    4342  class KernelFunction;
     43  class MatrixLookup;
     44  class MatrixLookupWeighted;
    4445
    4546  ///
     
    337338
    338339    std::vector<size_t> column_index_;
    339     const Kernel* kernel_;
    340     ///
    341     /// poiter telling how many owners to underlying data. NULL if
    342     /// this is not an owner.
    343     ///
    344     u_int* ref_count_;
     340    utility::SmartPtr<const Kernel> kernel_;
    345341    std::vector<size_t> row_index_;
    346342   
Note: See TracChangeset for help on using the changeset viewer.