Coverage Report

Created: 2026-03-31 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk/dcmdata/libsrc/dcwcache.cc
Line
Count
Source
1
/*
2
 *
3
 *  Copyright (C) 2007-2010, OFFIS e.V.
4
 *  All rights reserved.  See COPYRIGHT file for details.
5
 *
6
 *  This software and supporting documentation were developed by
7
 *
8
 *    OFFIS e.V.
9
 *    R&D Division Health
10
 *    Escherweg 2
11
 *    D-26121 Oldenburg, Germany
12
 *
13
 *
14
 *  Module:  dcmdata
15
 *
16
 *  Author:  Marco Eichelberg
17
 *
18
 *  Purpose: Implementation of class DcmWriteCache
19
 *
20
 */
21
22
23
#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */
24
25
#include "dcmtk/dcmdata/dcwcache.h"   /* for class DcmWriteCache */
26
#include "dcmtk/dcmdata/dcelem.h"     /* for class DcmElement */
27
#include "dcmtk/dcmdata/dcostrma.h"   /* for class DcmOutputStream */
28
29
30
void DcmWriteCache::init(void *owner,
31
                         Uint32 fieldLength,
32
                         Uint32 bytesTransferred,
33
                         E_ByteOrder byteOrder)
34
0
{
35
0
  if (! buf_)
36
0
  {
37
0
    capacity_ = DcmWriteCacheBufsize;
38
0
    buf_ = new Uint8[capacity_];
39
0
  }
40
41
0
  if (owner != owner_)
42
0
  {
43
0
    owner_ = owner;
44
0
    fieldLength_ = fieldLength;
45
0
    fieldOffset_ = bytesTransferred;
46
0
    byteOrder_ = byteOrder;
47
0
    offset_ = 0;
48
0
    numBytes_ = 0;
49
0
  }
50
0
}
51
52
OFCondition DcmWriteCache::fillBuffer(DcmElement& elem)
53
0
{
54
0
  OFCondition result = EC_Normal;
55
0
  if (buf_)
56
0
  {
57
      // re-fill the buffer only if completely empty
58
0
      if (! numBytes_)
59
0
      {
60
0
        offset_ = 0;
61
62
        // compute the number of bytes to read - either buffer size or
63
        // the remaining number of bytes in the element, whatever is smaller
64
0
        Uint32 bytesToRead = fieldLength_ - fieldOffset_;
65
0
        if (bytesToRead > capacity_) bytesToRead = capacity_;
66
67
0
        result = elem.getPartialValue(buf_, fieldOffset_, bytesToRead, &fcache_, byteOrder_);
68
69
0
        if (result.good())
70
0
        {
71
0
          numBytes_ = bytesToRead;
72
0
          fieldOffset_ += numBytes_;
73
0
        }
74
75
0
      }
76
0
  } else result = EC_IllegalCall;
77
0
  return result;
78
0
}
79
80
Uint32 DcmWriteCache::writeBuffer(DcmOutputStream &outStream)
81
0
{
82
0
  Uint32 result = 0;
83
0
  if (buf_ && numBytes_)
84
0
  {
85
0
    result = OFstatic_cast(Uint32, outStream.write(buf_ + offset_, numBytes_));
86
87
0
    numBytes_ -= result;
88
0
    offset_ += result;
89
0
  }
90
0
  return result;
91
0
}