File: dcwcache.cc

package info (click to toggle)
dcmtk 3.6.9-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,648 kB
  • sloc: ansic: 426,874; cpp: 318,177; makefile: 6,401; sh: 4,341; yacc: 1,026; xml: 482; lex: 321; perl: 277
file content (91 lines) | stat: -rw-r--r-- 2,186 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 *
 *  Copyright (C) 2007-2010, OFFIS e.V.
 *  All rights reserved.  See COPYRIGHT file for details.
 *
 *  This software and supporting documentation were developed by
 *
 *    OFFIS e.V.
 *    R&D Division Health
 *    Escherweg 2
 *    D-26121 Oldenburg, Germany
 *
 *
 *  Module:  dcmdata
 *
 *  Author:  Marco Eichelberg
 *
 *  Purpose: Implementation of class DcmWriteCache
 *
 */


#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#include "dcmtk/dcmdata/dcwcache.h"   /* for class DcmWriteCache */
#include "dcmtk/dcmdata/dcelem.h"     /* for class DcmElement */
#include "dcmtk/dcmdata/dcostrma.h"   /* for class DcmOutputStream */


void DcmWriteCache::init(void *owner,
                         Uint32 fieldLength,
                         Uint32 bytesTransferred,
                         E_ByteOrder byteOrder)
{
  if (! buf_)
  {
    capacity_ = DcmWriteCacheBufsize;
    buf_ = new Uint8[capacity_];
  }

  if (owner != owner_)
  {
    owner_ = owner;
    fieldLength_ = fieldLength;
    fieldOffset_ = bytesTransferred;
    byteOrder_ = byteOrder;
    offset_ = 0;
    numBytes_ = 0;
  }
}

OFCondition DcmWriteCache::fillBuffer(DcmElement& elem)
{
  OFCondition result = EC_Normal;
  if (buf_)
  {
      // re-fill the buffer only if completely empty
      if (! numBytes_)
      {
        offset_ = 0;

        // compute the number of bytes to read - either buffer size or
        // the remaining number of bytes in the element, whatever is smaller
        Uint32 bytesToRead = fieldLength_ - fieldOffset_;
        if (bytesToRead > capacity_) bytesToRead = capacity_;

        result = elem.getPartialValue(buf_, fieldOffset_, bytesToRead, &fcache_, byteOrder_);

        if (result.good())
        {
          numBytes_ = bytesToRead;
          fieldOffset_ += numBytes_;
        }

      }
  } else result = EC_IllegalCall;
  return result;
}

Uint32 DcmWriteCache::writeBuffer(DcmOutputStream &outStream)
{
  Uint32 result = 0;
  if (buf_ && numBytes_)
  {
    result = OFstatic_cast(Uint32, outStream.write(buf_ + offset_, numBytes_));

    numBytes_ -= result;
    offset_ += result;
  }
  return result;
}