[cig-commits] r13514 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Tue Dec 9 18:13:02 PST 2008
Author: luis
Date: 2008-12-09 18:13:02 -0800 (Tue, 09 Dec 2008)
New Revision: 13514
Modified:
cs/cigma/trunk/src/FunctionRegistry.cpp
cs/cigma/trunk/src/FunctionRegistry.h
Log:
Changed function registry to store shared pointers
Modified: cs/cigma/trunk/src/FunctionRegistry.cpp
===================================================================
--- cs/cigma/trunk/src/FunctionRegistry.cpp 2008-12-10 02:13:00 UTC (rev 13513)
+++ cs/cigma/trunk/src/FunctionRegistry.cpp 2008-12-10 02:13:02 UTC (rev 13514)
@@ -1,31 +1,30 @@
#include "FunctionRegistry.h"
-#include "fn_zero.h"
#include "Exception.h"
+#include "fn_zero.h"
+#include "fn_one.h"
+#include "fn_test.h"
using namespace cigma;
#include <cassert>
using namespace std;
+using boost::shared_ptr;
FunctionRegistry::FunctionRegistry()
{
//
// Initial set of functions
//
- ZeroFunction *zero = new ZeroFunction();
+ shared_ptr<ZeroFunction> zero(new ZeroFunction());
this->addFunction("zero", zero);
- /*
- UnitScalarFunction *one = new UnitScalarFunction();
+ shared_ptr<UnitScalarFn> one(new UnitScalarFn());
this->addFunction("one", one);
- typedef cigma::test_functions::Cube CubeBM
- CubeBM *cube = new CubeBM();
+ shared_ptr<CubeFn> cube(new CubeFn());
this->addFunction("test.cube", cube);
- typedef cigma::test_functions::Square SquareBM;
- SquareBM *square = new SquareBM();
+ shared_ptr<SquareFn> square(new SquareFn());
this->addFunction("test.square", square);
- // */
}
FunctionRegistry::~FunctionRegistry()
@@ -33,17 +32,13 @@
FunctionMap::iterator it;
for (it = functions.begin(); it != functions.end(); ++it)
{
- Function *fn = it->second;
- if (fn != 0)
- {
- delete fn;
- }
+ (it->second).reset();
}
}
-void FunctionRegistry::addFunction(std::string name, Function *function)
+void FunctionRegistry::addFunction(std::string name, shared_ptr<Function> function)
{
- assert(function != 0);
+ assert(function);
functions[name] = function;
}
@@ -53,9 +48,9 @@
return (it != functions.end());
}
-Function* FunctionRegistry::getFunction(std::string name)
+shared_ptr<Function> FunctionRegistry::getFunction(std::string name)
{
- Function *fn = 0;
+ shared_ptr<Function> fn;
FunctionMap::iterator it = functions.find(name);
if (it != functions.end())
{
Modified: cs/cigma/trunk/src/FunctionRegistry.h
===================================================================
--- cs/cigma/trunk/src/FunctionRegistry.h 2008-12-10 02:13:00 UTC (rev 13513)
+++ cs/cigma/trunk/src/FunctionRegistry.h 2008-12-10 02:13:02 UTC (rev 13514)
@@ -19,11 +19,12 @@
FunctionRegistry();
~FunctionRegistry();
- void addFunction(std::string name, Function *field);
+ void addFunction(std::string name, boost::shared_ptr<Function> field);
bool hasFunction(std::string name);
- Function* getFunction(std::string name);
+ boost::shared_ptr<Function> getFunction(std::string name);
- typedef std::map<std::string,Function*> FunctionMap;
+ typedef boost::shared_ptr<Function> function_sp;
+ typedef std::map<std::string,function_sp> FunctionMap;
FunctionMap functions;
};
More information about the CIG-COMMITS
mailing list