From 7aff1e4cb053394db57c2814d5fe1e6493e0cc75 Mon Sep 17 00:00:00 2001 From: watcherhd Date: Sat, 26 Nov 2011 14:19:43 +0000 Subject: Project folders rename part 2 git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@214 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- Dbx_tree/FileBTree.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Dbx_tree/FileBTree.h (limited to 'Dbx_tree/FileBTree.h') diff --git a/Dbx_tree/FileBTree.h b/Dbx_tree/FileBTree.h new file mode 100644 index 0000000..3a9e58a --- /dev/null +++ b/Dbx_tree/FileBTree.h @@ -0,0 +1,102 @@ +/* + +dbx_tree: tree database driver for Miranda IM + +Copyright 2007-2010 Michael "Protogenes" Kunz, + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#pragma once +#include "BTree.h" +#include "BlockManager.h" +#include "Logger.h" + +template +class CFileBTree : public CBTree +{ +private: + +protected: + CBlockManager & m_BlockManager; + uint16_t cSignature; + + virtual void PrepareInsertOperation(); + virtual TNode * CreateNewNode(TNodeRef & NodeRef); + virtual void DeleteNode(TNodeRef Node); + virtual TNode * Read(TNodeRef Node); + virtual void Write(TNodeRef Node); +public: + CFileBTree(CBlockManager & BlockManager, typename CBTree::TNodeRef RootNode, uint16_t Signature); + virtual ~CFileBTree(); +}; + + + + +template +CFileBTree::CFileBTree(CBlockManager & BlockManager, typename CBTree::TNodeRef RootNode, uint16_t Signature) +: CBTree::CBTree(RootNode), + m_BlockManager(BlockManager) +{ + cSignature = Signature; + CBTree::m_DestroyTree = false; +} + +template +CFileBTree::~CFileBTree() +{ + CBTree::m_DestroyTree = false; +} + + +template +void CFileBTree::PrepareInsertOperation() +{ + +} + +template +typename CBTree::TNode * CFileBTree::CreateNewNode(typename CBTree::TNodeRef & NodeRef) +{ + return reinterpret_cast( m_BlockManager.CreateBlock(NodeRef, cSignature << 16, sizeof(typename CBTree::TNode) - 4) - 1); +} + +template +void CFileBTree::DeleteNode(typename CBTree::TNodeRef Node) +{ + m_BlockManager.DeleteBlock(Node); +} + +template +typename CBTree::TNode * CFileBTree::Read(typename CBTree::TNodeRef Node) +{ + uint32_t sig = 0; + uint32_t size = 0; + TNode * res = reinterpret_cast( m_BlockManager.ReadBlock(Node, size, sig) - 1); /// HACK using knowledge about the blockmanager here + + CHECK(res->Signature == cSignature, + logCRITICAL, _T("Signature check failed")); + + return res; +} + +template +void CFileBTree::Write(typename CBTree::TNodeRef Node) +{ + m_BlockManager.UpdateBlock(Node, 0); +} + -- cgit v1.2.3