dcmtkpp
Writer.h
1 /*************************************************************************
2  * dcmtkpp - Copyright (C) Universite de Strasbourg
3  * Distributed under the terms of the CeCILL-B license, as published by
4  * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6  * for details.
7  ************************************************************************/
8 
9 #ifndef _ca5c06d2_04f9_4009_9e98_5607e1060379
10 #define _ca5c06d2_04f9_4009_9e98_5607e1060379
11 
12 #include <ostream>
13 #include <string>
14 
15 #include "dcmtkpp/DataSet.h"
16 #include "dcmtkpp/Element.h"
17 #include "dcmtkpp/Tag.h"
18 #include "dcmtkpp/Value.h"
19 #include "dcmtkpp/VR.h"
20 
21 namespace dcmtkpp
22 {
23 
25 class Writer
26 {
27 public:
29  enum class ItemEncoding
30  {
31  ExplicitLength,
32  UndefinedLength
33  };
34 
36  std::ostream & stream;
37 
46 
48  Writer(
49  std::ostream & stream,
50  int byte_ordering, bool explicit_vr,
51  ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
52  bool use_group_length=false);
53 
58  Writer(
59  std::ostream & stream,
60  std::string const & transfer_syntax,
61  ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
62  bool use_group_length=false);
63 
65  void write_data_set(DataSet const & data_set) const;
66 
68  void write_tag(Tag const & tag) const;
69 
71  void write_element(Element const & element) const;
72 
74  static void write_file(
75  DataSet const &data_set, std::ostream & stream,
76  std::string const & transfer_syntax,
77  ItemEncoding item_encoding=ItemEncoding::ExplicitLength,
78  bool use_group_length=false);
79 
80 private:
81 
82  struct Visitor
83  {
84  typedef void result_type;
85 
86  std::ostream & stream;
87  VR vr;
88 
89  int byte_ordering;
90  bool explicit_vr;
92  bool use_group_length;
93 
94  Visitor(
95  std::ostream & stream, VR vr,
96  int byte_ordering, bool explicit_vr, ItemEncoding item_encoding,
97  bool use_group_length);
98 
99  result_type operator()(Value::Integers const & value) const;
100  result_type operator()(Value::Reals const & value) const;
101  result_type operator()(Value::Strings const & value) const;
102  result_type operator()(Value::DataSets const & value) const;
103  result_type operator()(Value::Binary const & value) const;
104 
105  template<typename T>
106  void write_strings(T const & sequence, char padding) const;
107  };
108 };
109 
110 }
111 
112 #endif // _ca5c06d2_04f9_4009_9e98_5607e1060379
std::vector< DataSet > DataSets
Data sets container.
Definition: Value.h:55
Definition: Association.cpp:22
Write DICOM objects to a stream.
Definition: Writer.h:25
bool explicit_vr
Explicit-ness of the Value Representations.
Definition: Writer.h:41
ItemEncoding
Encodings of sequence items.
Definition: Writer.h:29
std::vector< String > Strings
String container.
Definition: Value.h:52
static void write_file(DataSet const &data_set, std::ostream &stream, std::string const &transfer_syntax, ItemEncoding item_encoding=ItemEncoding::ExplicitLength, bool use_group_length=false)
Write a file (meta-information and data set).
Definition: Writer.cpp:202
DICOM Data set.
Definition: DataSet.h:66
Element of a DICOM data set.
Definition: Element.h:25
void write_data_set(DataSet const &data_set) const
Write a data set.
Definition: Writer.cpp:80
int byte_ordering
Endianness (LITTLE_ENDIAN or BIG_ENDIAN).
Definition: Writer.h:39
Writer(std::ostream &stream, int byte_ordering, bool explicit_vr, ItemEncoding item_encoding=ItemEncoding::ExplicitLength, bool use_group_length=false)
Build a writer.
Definition: Writer.cpp:53
std::vector< Real > Reals
Real container.
Definition: Value.h:49
void write_element(Element const &element) const
Write an element (VR, VL and value).
Definition: Writer.cpp:139
ItemEncoding item_encoding
Encoding of sequence items.
Definition: Writer.h:43
bool use_group_length
Presence of group length elements.
Definition: Writer.h:45
void write_tag(Tag const &tag) const
Write a tag.
Definition: Writer.cpp:131
A DICOM element tag.
Definition: Tag.h:22
std::vector< Integer > Integers
Integer container.
Definition: Value.h:46
std::ostream & stream
Output stream.
Definition: Writer.h:36
std::vector< uint8_t > Binary
Binary data container.
Definition: Value.h:58