/**
       * The destructor only deletes the pointers if count reaches zero.
       */
      ~fsolver(){
	if( count == 0 or --*count == 0 ){
	  // could have allocated null pointer
	  if( ccgsl_pointer != 0 ) gsl_multifit_fsolver_free( ccgsl_pointer );
	  delete count;
	}
      }
      /**
       * The assignment operator. This copies elementwise.
       * @param v The fsolver to copy
       */
      fsolver& operator=( fsolver const& v ){
	// first, possibly delete anything pointed to by this
	if( count == 0 or --*count == 0 ){
	  if( ccgsl_pointer != 0 ) gsl_multifit_fsolver_free( ccgsl_pointer );
	  delete count;
	} // Then copy
	ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
      }
      /**
       * The default constructor creates a new fsolver with n elements.
       * @param T The fsolver type.
       * @param n The number of elements in the fsolver.
       * @param p The number of predictor variables
       */
      explicit fsolver( type const* T, size_t const n, size_t const p ){
	ccgsl_pointer = gsl_multifit_fsolver_alloc( T, n, p );
	// just plausibly we could allocate fsolver but not count
	try { count = new size_t; } catch( std::bad_alloc& e ){
	  // try to tidy up before rethrowing
	  gsl_multifit_fsolver_free( ccgsl_pointer );
	  throw e;
	}
	*count = 1; // initially there is just one reference to ccgsl_pointer
      }
Beispiel #4
0
void MultiFitter::CleanUp()
{
	if(s!=NULL) { gsl_multifit_fdfsolver_free (s); s=NULL; }
	if(sf!=NULL) { gsl_multifit_fsolver_free (sf); sf=NULL; }
}