X-Git-Url: http://git.indexdata.com/?p=yazpp-moved-to-github.git;a=blobdiff_plain;f=src%2Fgdu.cpp;h=d84a45e5d12d590d686d37d1dbb01026dfce1a58;hp=084c8c5c81982e0505db9f8e693b48a938b59209;hb=711105a336b155f2b7f098cf84f2e30952cb8588;hpb=7411ed6df7fc0b535f83503f73d70e80f390e295 diff --git a/src/gdu.cpp b/src/gdu.cpp index 084c8c5..d84a45e 100644 --- a/src/gdu.cpp +++ b/src/gdu.cpp @@ -1,11 +1,12 @@ -/* - * Copyright (c) 1998-2005, Index Data. +/* This file is part of the yazpp toolkit. + * Copyright (C) 1998-2012 Index Data and Mike Taylor * See the file LICENSE for details. - * - * $Id: gdu.cpp,v 1.2 2005-06-25 15:53:19 adam Exp $ */ -#include +#if HAVE_CONFIG_H +#include +#endif +#include using namespace yazpp_1; @@ -23,33 +24,66 @@ 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); - + odr_setbuf(m_decode, buf, len, 0); z_GDU(m_decode, &m_gdu, 0, 0); } odr_destroy(encode); } +int GDU::get_size() +{ + int len = 0; + ODR encode = odr_createmem(ODR_ENCODE); + if (m_gdu && z_GDU(encode, &m_gdu, 0, "encode")) + odr_getbuf(encode, &len, 0); + odr_destroy(encode); + return len; +} + +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,56 +91,10 @@ 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 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab