implemented delete correction for leaks
This commit is contained in:
@@ -23,17 +23,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
// global declarations
|
||||
// ************************************
|
||||
extern std::vector<A_test*> test_list;
|
||||
extern void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||
|
||||
|
||||
// struct for tests
|
||||
// ***************************************
|
||||
struct mystruct {
|
||||
public:
|
||||
mystruct(int data = 0) {_val = new int[5]; _val[0] = data;}
|
||||
mystruct(int data = 0) {_val = new int[2]; _val[0] = data; _val[1] = data;}
|
||||
~mystruct() {delete[] _val;}
|
||||
int * get_data() const {return _val;}
|
||||
private:
|
||||
@@ -41,11 +35,21 @@ private:
|
||||
};
|
||||
//extern std::ostream & operator<<(std::ostream & o, mystruct const & rhs);
|
||||
std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
||||
o << (*rhs).get_data()[0];
|
||||
if (rhs != NULL)
|
||||
o << (*rhs).get_data()[0] << "," << (*rhs).get_data()[1];
|
||||
else
|
||||
o << "NULL";
|
||||
return (o);
|
||||
}
|
||||
|
||||
|
||||
// global declarations
|
||||
// ************************************
|
||||
extern std::vector<A_test*> test_list;
|
||||
extern void add_to_list(std::string s, A_test* s1, A_test* s2, A_test* s3, A_test* s4);
|
||||
std::vector<mystruct*> mem_list_struct;
|
||||
|
||||
|
||||
// adding each test to the list
|
||||
// ***************************
|
||||
#define TEST(f_name) \
|
||||
@@ -67,7 +71,8 @@ std::ostream & operator<<(std::ostream & o, mystruct const * rhs) {
|
||||
// ****************************************
|
||||
# define TITLE(s) std::cout << "\n" B_PURPLE #s RESET "\n\n";
|
||||
# define VAL(n) val<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n)
|
||||
# define PRINT(n) print_vector<T>(n);
|
||||
# define DELETE delete_structs();
|
||||
|
||||
|
||||
// get a value
|
||||
@@ -94,22 +99,39 @@ template <>
|
||||
}
|
||||
template <>
|
||||
mystruct* val(int n) {
|
||||
|
||||
return ( new mystruct(n) );
|
||||
|
||||
mystruct *s = new mystruct(n);
|
||||
mem_list_struct.push_back(s);
|
||||
return ( s );
|
||||
}
|
||||
|
||||
|
||||
// get a value
|
||||
// *********************************************
|
||||
template <class T>
|
||||
void print_vector(ft::vector<T> vec)
|
||||
{
|
||||
void print_vector(ft::vector<T> vec) {
|
||||
|
||||
int i = 0;
|
||||
for (typename ft::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it, i++)
|
||||
typename ft::vector<T>::iterator it;
|
||||
typename ft::vector<T>::iterator it_end = vec.end();
|
||||
|
||||
for (it = vec.begin(); it != it_end; ++it, i++)
|
||||
std::cout << "[" << i << "]" << *it << " ";
|
||||
std::cout << "\nsize:" << vec.size() << " capacty:" << vec.capacity() << "\n";
|
||||
}
|
||||
|
||||
|
||||
// delete vector elements
|
||||
// **********************************
|
||||
void delete_structs() {
|
||||
|
||||
std::vector<mystruct*>::iterator it;
|
||||
std::vector<mystruct*>::iterator it_end = mem_list_struct.end();
|
||||
|
||||
for (it = mem_list_struct.begin(); it != it_end; ++it)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user