~ubuntu-branches/ubuntu/trusty/cmake3/trusty-updates

« back to all changes in this revision

Viewing changes to Source/cmXMLWriter.h

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2017-02-23 17:55:24 UTC
  • Revision ID: package-import@ubuntu.com-20170223175524-5nh7s4pu97fsa0t7
Tags: upstream-3.5.1
ImportĀ upstreamĀ versionĀ 3.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*============================================================================
 
2
  CMake - Cross Platform Makefile Generator
 
3
  Copyright 2015 Daniel Pfeifer <daniel@pfeifer-mail.de>
 
4
 
 
5
  Distributed under the OSI-approved BSD License (the "License");
 
6
  see accompanying file Copyright.txt for details.
 
7
 
 
8
  This software is distributed WITHOUT ANY WARRANTY; without even the
 
9
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
10
  See the License for more information.
 
11
============================================================================*/
 
12
#ifndef cmXMLWiter_h
 
13
#define cmXMLWiter_h
 
14
 
 
15
#include "cmStandardIncludes.h"
 
16
#include "cmXMLSafe.h"
 
17
 
 
18
#include <ostream>
 
19
#include <stack>
 
20
#include <string>
 
21
#include <vector>
 
22
 
 
23
class cmXMLWriter
 
24
{
 
25
public:
 
26
  cmXMLWriter(std::ostream& output, std::size_t level = 0);
 
27
  ~cmXMLWriter();
 
28
 
 
29
  void StartDocument(const char* encoding = "UTF-8");
 
30
  void EndDocument();
 
31
 
 
32
  void StartElement(std::string const& name);
 
33
  void EndElement();
 
34
 
 
35
  void BreakAttributes();
 
36
 
 
37
  template <typename T>
 
38
  void Attribute(const char* name, T const& value)
 
39
    {
 
40
    this->PreAttribute();
 
41
    this->Output << name << "=\"" << SafeAttribute(value) << '"';
 
42
    }
 
43
 
 
44
  template <typename T>
 
45
  void Element(std::string const& name, T const& value)
 
46
    {
 
47
    this->StartElement(name);
 
48
    this->Content(value);
 
49
    this->EndElement();
 
50
    }
 
51
 
 
52
  template <typename T>
 
53
  void Content(T const& content)
 
54
    {
 
55
    this->PreContent();
 
56
    this->Output << SafeContent(content);
 
57
    }
 
58
 
 
59
  void Comment(const char* comment);
 
60
 
 
61
  void CData(std::string const& data);
 
62
 
 
63
  void ProcessingInstruction(const char* target, const char* data);
 
64
 
 
65
  void FragmentFile(const char* fname);
 
66
 
 
67
private:
 
68
  cmXMLWriter(const cmXMLWriter&);
 
69
  cmXMLWriter& operator=(const cmXMLWriter&);
 
70
 
 
71
  void ConditionalLineBreak(bool condition, std::size_t indent);
 
72
 
 
73
  void PreAttribute();
 
74
  void PreContent();
 
75
 
 
76
  void CloseStartElement();
 
77
 
 
78
private:
 
79
  static cmXMLSafe SafeAttribute(const char* value)
 
80
    {
 
81
    return cmXMLSafe(value);
 
82
    }
 
83
 
 
84
  static cmXMLSafe SafeAttribute(std::string const& value)
 
85
    {
 
86
    return cmXMLSafe(value);
 
87
    }
 
88
 
 
89
  template <typename T>
 
90
  static T SafeAttribute(T value)
 
91
    {
 
92
    return value;
 
93
    }
 
94
 
 
95
  static cmXMLSafe SafeContent(const char* value)
 
96
    {
 
97
    return cmXMLSafe(value).Quotes(false);
 
98
    }
 
99
 
 
100
  static cmXMLSafe SafeContent(std::string const& value)
 
101
    {
 
102
    return cmXMLSafe(value).Quotes(false);
 
103
    }
 
104
 
 
105
  template <typename T>
 
106
  static T SafeContent(T value)
 
107
    {
 
108
    return value;
 
109
    }
 
110
 
 
111
private:
 
112
  std::ostream& Output;
 
113
  std::stack<std::string, std::vector<std::string> > Elements;
 
114
  std::size_t Level;
 
115
  bool ElementOpen;
 
116
  bool BreakAttrib;
 
117
  bool IsContent;
 
118
};
 
119
 
 
120
#endif