Added copy assignment and copy constructor for GDU class.
pkginclude_HEADERS = \
gdu.h \
+ gduqueue.h \
ir-assoc.h \
pdu-assoc.h \
pdu-observer.h \
* 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
#include <yaz/proto.h>
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
--- /dev/null
+/*
+ * 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 <yaz/yconfig.h>
+
+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
+ */
+
-## $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
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
* 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 <yaz++/gdu.h>
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);
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();
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
--- /dev/null
+/*
+ * 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 <yaz++/gdu.h>
+#include <yaz++/gduqueue.h>
+
+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
+ */
+