From ce024cc2ec8438c906824afe3a634d928b5cf92e Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Wed, 23 Nov 2005 04:17:51 +0000 Subject: [PATCH] UNDO: Cambio constructor por metodo estatico. Cambio el constructor de "abrir" por un metodo estatico Open. Esto tiene la ventaja que si el archivo a abrir no es un arbol B no se crea un arbol inconsistente y se elimina posible error de uso. --- src/btree.cpp | 29 ++++++++--------------------- src/btree.h | 6 +----- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/btree.cpp b/src/btree.cpp index 2701b3a..ae68316 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -36,54 +36,41 @@ BTree::BTree (const std::string &name, unsigned int block_size, int tt, int kt, delete [] node; } -BTree* BTree::Open (const std::string &name) +BTree::BTree (const std::string &name) { /* Leo los bloques recuperables */ - FILE *fp; - BTree *tree = new BTree (); - - std::string del = name + ".del"; + std::string del = filename + ".del"; fp = fopen (del.c_str (), "wb"); if (fp != NULL) { uint i; while (fread (&i, 1, sizeof (uint), fp)) { - tree->deleted_nodes.push_back (i); + deleted_nodes.push_back (i); } fclose (fp); } - del = name + ".blockdel"; + del = filename + ".blockdel"; fp = fopen (del.c_str (), "wb"); if (fp != NULL) { uint i; while (fread (&i, 1, sizeof (uint), fp)) { - tree->deleted_block_data.push_back (i); + deleted_block_data.push_back (i); } fclose (fp); } - tree->filename = name; - tree->fp = fopen (name.c_str(), "rb+"); + fp = fopen (name.c_str(), "rb+"); if (!fp) { /* TODO : mandar una exception ? */ - delete tree; - return NULL; - } - tree->ReadFileHeader (); - - if (strcmp ("DILUMA", tree->header.magic)) { - /* Arbol no tiene magic!! */ - delete tree; - return NULL; + return; } - - return tree; + ReadFileHeader (); } BTree::~BTree () diff --git a/src/btree.h b/src/btree.h index 526b428..9e49213 100644 --- a/src/btree.h +++ b/src/btree.h @@ -251,8 +251,7 @@ struct BTreeFindResult { class BTree { public: BTree (const std::string &filename, unsigned int block_size, int t_t = TYPE_IDENTIFICACION, int k_t = KEY_FIXED, bool create_new_file = false); - - static BTree *Open (const std::string &filename); + BTree (const std::string &filename); ~BTree (); @@ -334,9 +333,6 @@ class BTree { /* DEBUG */ - private: - BTree () {} - public: void PrintNode (uint num); }; -- 2.43.0