delete [] node;
}
-BTree::BTree (const std::string &name)
+BTree* BTree::Open (const std::string &name)
{
/* Leo los bloques recuperables */
- std::string del = filename + ".del";
+ FILE *fp;
+ BTree *tree = new BTree ();
+
+ std::string del = name + ".del";
fp = fopen (del.c_str (), "wb");
if (fp != NULL) {
uint i;
while (fread (&i, 1, sizeof (uint), fp)) {
- deleted_nodes.push_back (i);
+ tree->deleted_nodes.push_back (i);
}
fclose (fp);
}
- del = filename + ".blockdel";
+ del = name + ".blockdel";
fp = fopen (del.c_str (), "wb");
if (fp != NULL) {
uint i;
while (fread (&i, 1, sizeof (uint), fp)) {
- deleted_block_data.push_back (i);
+ tree->deleted_block_data.push_back (i);
}
fclose (fp);
}
- fp = fopen (name.c_str(), "rb+");
+ tree->filename = name;
+ tree->fp = fopen (name.c_str(), "rb+");
if (!fp) {
/* TODO : mandar una exception ? */
- return;
+ delete tree;
+ return NULL;
}
- ReadFileHeader ();
+ tree->ReadFileHeader ();
+
+ if (strcmp ("DILUMA", tree->header.magic)) {
+ /* Arbol no tiene magic!! */
+ delete tree;
+ return NULL;
+ }
+
+ return tree;
}
BTree::~BTree ()
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);
- BTree (const std::string &filename);
+
+ static BTree *Open (const std::string &filename);
~BTree ();
/* DEBUG */
+ private:
+ BTree () {}
+
public:
void PrintNode (uint num);
};