summaryrefslogtreecommitdiff
path: root/xsd/xsd.hxx
blob: 43f38ea241cb8d1ded476cb7b92ad75bae03182c (plain)
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
// file      : xsd/xsd.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_HXX
#define XSD_HXX

#include <set>
#include <vector>
#include <cstdio> // std::remove

#include <cutl/shared-ptr.hxx>

#include <xsd-frontend/semantic-graph/elements.hxx> // Path

#include <types.hxx>

typedef std::set<NarrowString> WarningSet;
typedef std::vector<NarrowString> FileList;

//
//
struct AutoUnlink
{
  AutoUnlink (XSDFrontend::SemanticGraph::Path const& file)
      : file_ (file), canceled_ (false)
  {
  }

  ~AutoUnlink ()
  {
    if (!canceled_)
      std::remove (file_.native_file_string ().c_str ());
  }

  void
  cancel ()
  {
    canceled_ = true;
  }

private:
  XSDFrontend::SemanticGraph::Path file_;
  bool canceled_;
};

//
//
struct AutoUnlinks
{
  void
  add (XSDFrontend::SemanticGraph::Path const& file)
  {
    unlinks_.push_back(
      cutl::shared_ptr<AutoUnlink> (
        new (shared) AutoUnlink (file)));
  }

  void
  cancel ()
  {
    for (Unlinks::iterator i (unlinks_.begin ()); i != unlinks_.end (); ++i)
      (*i)->cancel ();
  }

private:
  typedef std::vector<cutl::shared_ptr<AutoUnlink> > Unlinks;
  Unlinks unlinks_;
};

#endif // XSD_HXX