From b03c09ff93152fb9387281ad5431e6b4d44f16cd Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 13 Oct 2005 09:56:38 +0000 Subject: [PATCH] Class GDUQueue in separate header/source. Added copy assignment and copy constructor for GDU class. --- include/yaz++/Makefile.am | 1 + include/yaz++/gdu.h | 29 ++++------------- include/yaz++/gduqueue.h | 43 ++++++++++++++++++++++++ src/Makefile.am | 4 +-- src/gdu.cpp | 79 ++++++++++++++++----------------------------- src/gduqueue.cpp | 66 +++++++++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 76 deletions(-) create mode 100644 include/yaz++/gduqueue.h create mode 100644 src/gduqueue.cpp diff --git a/include/yaz++/Makefile.am b/include/yaz++/Makefile.am index 1d36b1e..97de725 100644 --- a/include/yaz++/Makefile.am +++ b/include/yaz++/Makefile.am @@ -1,6 +1,7 @@ pkginclude_HEADERS = \ gdu.h \ + gduqueue.h \ ir-assoc.h \ pdu-assoc.h \ pdu-observer.h \ diff --git a/include/yaz++/gdu.h b/include/yaz++/gdu.h index 7512bf0..5d20b91 100644 --- a/include/yaz++/gdu.h +++ b/include/yaz++/gdu.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: gdu.h,v 1.2 2005-06-25 15:53:19 adam Exp $ + * $Id: gdu.h,v 1.3 2005-10-13 09:56:38 adam Exp $ */ #ifndef YAZPP_GDU_INCLUDED @@ -12,38 +12,21 @@ #include namespace yazpp_1 { - class YAZ_EXPORT GDU { public: + GDU(const GDU &); GDU(Z_GDU *gdu); GDU(Z_APDU *apdu); + GDU(); ~GDU(); - Z_GDU *get(); - void extract_odr_to(ODR dst); + GDU &operator=(const GDU &); + Z_GDU *get() const; + void move_away_gdu(ODR dst, Z_GDU **gdu); private: void base(Z_GDU *gdu, ODR o); Z_GDU *m_gdu; ODR m_decode; }; - - class GDUQueue_List { - friend class GDUQueue; - private: - GDU *m_item; - GDUQueue_List *m_next; - }; - - class GDUQueue { - public: - GDUQueue(); - ~GDUQueue(); - void clear(); - void enqueue(GDU *gdu); - GDU *dequeue(); - int size(); - private: - GDUQueue_List *m_list; - }; }; #endif diff --git a/include/yaz++/gduqueue.h b/include/yaz++/gduqueue.h new file mode 100644 index 0000000..e05ec45 --- /dev/null +++ b/include/yaz++/gduqueue.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1998-2005, Index Data. + * See the file LICENSE for details. + * + * $Id: gduqueue.h,v 1.1 2005-10-13 09:56:38 adam Exp $ + */ + +#ifndef YAZPP_GDUQUEUE_INCLUDED +#define YAZPP_GDUQUEUE_INCLUDED + +#include + +namespace yazpp_1 { + class GDU; + class GDUQueue_List { + friend class GDUQueue; + private: + GDU *m_item; + GDUQueue_List *m_next; + }; + + class GDUQueue { + public: + GDUQueue(); + ~GDUQueue(); + void clear(); + void enqueue(GDU *gdu); + GDU *dequeue(); + int size(); + private: + GDUQueue_List *m_list; + }; +}; + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/Makefile.am b/src/Makefile.am index e429145..6d49470 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.28 2005-09-27 17:57:51 adam Exp $ +## $Id: Makefile.am,v 1.29 2005-10-13 09:56:38 adam Exp $ check_PROGRAMS = tstquery noinst_PROGRAMS = yaz-my-server yaz-my-client @@ -19,7 +19,7 @@ libyazcpp_la_SOURCES=socket-observer.cpp pdu-observer.cpp query.cpp \ yaz-z-assoc.cpp yaz-z-query.cpp yaz-ir-assoc.cpp \ yaz-z-server.cpp yaz-pdu-assoc-thread.cpp yaz-z-server-sr.cpp \ yaz-z-server-ill.cpp yaz-z-server-update.cpp yaz-z-databases.cpp \ - yaz-z-cache.cpp yaz-cql2rpn.cpp gdu.cpp + yaz-z-cache.cpp yaz-cql2rpn.cpp gdu.cpp gduqueue.cpp yaz_my_client_SOURCES=yaz-my-client.cpp diff --git a/src/gdu.cpp b/src/gdu.cpp index 084c8c5..1f660ea 100644 --- a/src/gdu.cpp +++ b/src/gdu.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2005, Index Data. * See the file LICENSE for details. * - * $Id: gdu.cpp,v 1.2 2005-06-25 15:53:19 adam Exp $ + * $Id: gdu.cpp,v 1.3 2005-10-13 09:56:38 adam Exp $ */ #include @@ -23,11 +23,21 @@ GDU::GDU(Z_GDU *gdu) base(gdu, odr_createmem(ODR_ENCODE)); } +GDU::GDU() +{ + base(0, odr_createmem(ODR_ENCODE)); +} + +GDU::GDU(const GDU &g) +{ + base(g.get(), odr_createmem(ODR_ENCODE)); +} + void GDU::base(Z_GDU *gdu, ODR encode) { m_decode = odr_createmem(ODR_DECODE); m_gdu = 0; - if (z_GDU(encode, &gdu, 0, "encode")) + if (gdu && z_GDU(encode, &gdu, 0, "encode")) { int len; char *buf = odr_getbuf(encode, &len, 0); @@ -38,18 +48,32 @@ void GDU::base(Z_GDU *gdu, ODR encode) odr_destroy(encode); } + +GDU &GDU::operator=(const GDU &g) +{ + if (this != &g) + { + odr_destroy(m_decode); + + base(g.get(), odr_createmem(ODR_ENCODE)); + } + return *this; +} + GDU::~GDU() { odr_destroy(m_decode); } -Z_GDU *GDU::get() +Z_GDU *GDU::get() const { return m_gdu; } -void GDU::extract_odr_to(ODR dst) +void GDU::move_away_gdu(ODR dst, Z_GDU **gdu) { + *gdu = m_gdu; + m_gdu = 0; NMEM nmem = odr_extract_mem(m_decode); if (!dst->mem) dst->mem = nmem_create(); @@ -57,53 +81,6 @@ void GDU::extract_odr_to(ODR dst) nmem_destroy(nmem); } - -GDUQueue::GDUQueue() -{ - m_list = 0; -} - -int GDUQueue::size() -{ - int no = 0; - GDUQueue_List *l; - for (l = m_list; l; l = l->m_next) - no++; - return no; -} - -void GDUQueue::enqueue(GDU *gdu) -{ - GDUQueue_List *l = new GDUQueue_List; - l->m_next = m_list; - l->m_item = gdu; - m_list = l; -} - -GDU *GDUQueue::dequeue() -{ - GDUQueue_List **l = &m_list; - if (!*l) - return 0; - while ((*l)->m_next) - l = &(*l)->m_next; - GDU *m = (*l)->m_item; - delete *l; - *l = 0; - return m; -} - -void GDUQueue::clear() -{ - GDU *g; - while ((g = dequeue())) - delete g; -} - -GDUQueue::~GDUQueue() -{ - clear(); -} /* * Local variables: * c-basic-offset: 4 diff --git a/src/gduqueue.cpp b/src/gduqueue.cpp new file mode 100644 index 0000000..b0886cb --- /dev/null +++ b/src/gduqueue.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1998-2005, Index Data. + * See the file LICENSE for details. + * + * $Id: gduqueue.cpp,v 1.1 2005-10-13 09:56:38 adam Exp $ + */ + +#include +#include + +using namespace yazpp_1; + +GDUQueue::GDUQueue() +{ + m_list = 0; +} + +int GDUQueue::size() +{ + int no = 0; + GDUQueue_List *l; + for (l = m_list; l; l = l->m_next) + no++; + return no; +} + +void GDUQueue::enqueue(GDU *gdu) +{ + GDUQueue_List *l = new GDUQueue_List; + l->m_next = m_list; + l->m_item = gdu; + m_list = l; +} + +GDU *GDUQueue::dequeue() +{ + GDUQueue_List **l = &m_list; + if (!*l) + return 0; + while ((*l)->m_next) + l = &(*l)->m_next; + GDU *m = (*l)->m_item; + delete *l; + *l = 0; + return m; +} + +void GDUQueue::clear() +{ + GDU *g; + while ((g = dequeue())) + delete g; +} + +GDUQueue::~GDUQueue() +{ + clear(); +} +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + -- 1.7.10.4