From 1b6152a8b901df0e8b57c35b9846a6e609b8b7df Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 12 Sep 2005 05:08:45 +0000 Subject: [PATCH] Agrego estructura basica para manejo de claves La idea es que el manejo sea transparente a travez del tipo "Clave" y toda la magia la haga los objetitos. --- src/Makefile | 5 +++-- src/btree.h | 2 +- src/clave.h | 17 +++++++++++++++++ src/clave_fija.cpp | 17 +++++++++++++++++ src/clave_fija.h | 19 +++++++++++++++++++ src/common.h | 9 +++++++++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/clave.h create mode 100644 src/clave_fija.cpp create mode 100644 src/clave_fija.h create mode 100644 src/common.h diff --git a/src/Makefile b/src/Makefile index 5440d99..cd9cbe7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,5 +3,6 @@ CXXFLAGS=-Wall -g all: $(TARGET) -$(TARGET): main.o btree.o - g++ -o $(TARGET) main.o btree.o +$(TARGET): main.o btree.o clave_fija.o + g++ -o $(TARGET) main.o btree.o clave_fija.o + diff --git a/src/btree.h b/src/btree.h index 0ed4fbd..744079b 100644 --- a/src/btree.h +++ b/src/btree.h @@ -45,9 +45,9 @@ */ #include +#include "common.h" /* alias para codear menos :) */ -typedef unsigned char uchar; /** Encabezado del archivo BTree */ typedef struct _btree_file_ { diff --git a/src/clave.h b/src/clave.h new file mode 100644 index 0000000..7cf3ceb --- /dev/null +++ b/src/clave.h @@ -0,0 +1,17 @@ + +#ifndef _CLAVE_H_ +#define _CLAVE_H_ + +/* Clave para agregar a un arbol B */ +#include "common.h" + +class Clave { + public: + virtual ~Clave () {} + + virtual uint Size () = 0; + virtual uchar *ToArray () = 0; +}; + +#endif + diff --git a/src/clave_fija.cpp b/src/clave_fija.cpp new file mode 100644 index 0000000..05c9814 --- /dev/null +++ b/src/clave_fija.cpp @@ -0,0 +1,17 @@ + +#include +#include "clave_fija.h" + +uint ClaveFija::Size () +{ + return sizeof (int); +} + +uchar *ClaveFija::ToArray () +{ + uchar *out; + out = new uchar[sizeof(int)]; + memcpy (out, &data, sizeof(int)); + return out; +} + diff --git a/src/clave_fija.h b/src/clave_fija.h new file mode 100644 index 0000000..b11fe22 --- /dev/null +++ b/src/clave_fija.h @@ -0,0 +1,19 @@ + +#ifndef _CLAVE_FIJA_H_ +#define _CLAVE_FIJA_H_ + +#include "clave.h" + +class ClaveFija : Clave { + public : + virtual ~ClaveFija () {} + + virtual uint Size (); + virtual uchar *ToArray (); + + private: + int data; +}; + +#endif + diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..6e7079f --- /dev/null +++ b/src/common.h @@ -0,0 +1,9 @@ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +typedef unsigned char uchar; +typedef unsigned int uint; + +#endif + -- 2.43.0