A set of classes to facilitate easy, automatic resource
disposal and handling.
Toggle if(true) / if(false) in CleanerDebug::msg to
enable / disable debug output.
Usage Example
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include "cleaner.h"
using std::string;
using std::cout;
using std::endl;
using std::vector;
class Foo
{
public: virtual ~Foo() { cout << "~Foo()" << endl; }
};
class Bar : public Foo
{
public: ~Bar() { cout << "~Bar()" << endl; }
};
int main()
{
Cleaner cleaner;
FILE *f = fopen(__FILE__, "r");
if(!f)
{
cout << "Could not open file: [" << __FILE__ << "]" << endl;
return(1);
}
int fileIndex = cleaner.addFile(f);
int *iPtr = new int;
cleaner.addPointer(iPtr);
double *dArray = new double[100];
cleaner.addArray(dArray);
vector<Foo *> v;
v.push_back(new Bar());
v.push_back(new Bar());
v.push_back(new Bar());
cleaner.addPointerVector(v);
if(false)
{
if(!cleaner.removeEntry(fileIndex))
{
cout << "Invalid entry index: [" << fileIndex << "]" << endl;
}
else
{
cout << "fclose(" << f << ")" << endl;
fclose(f);
}
}
return(0);
}
Example Output
Cleaner()
~Cleaner() => delete(004204B0)
~FileCleanerEntry() => fclose(00418738)
~CleanerEntry()
~Cleaner() => delete(00420480)
~PointerCleanerEntry() => delete(0040828F)
~CleanerEntry()
~Cleaner() => delete(004204A0)
~ArrayCleanerEntry() => delete [] (003208DC)
~CleanerEntry()
~Cleaner() => delete(004202E0)
~PointerVectorCleanerEntry() => delete(00420470)
~Bar()
~Foo()
~PointerVectorCleanerEntry() => delete(00420430)
~Bar()
~Foo()
~PointerVectorCleanerEntry() => delete(00420440)
~Bar()
~Foo()
~CleanerEntry()
Source Code
Return to Main |