summaryrefslogtreecommitdiff
path: root/xsd/xsd.hxx
blob: f09b18d39b463588dd5434fd100f9422e126ef66 (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
73
74
75
76
77
78
79
80
// file      : xsd/xsd.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_HXX
#define XSD_HXX

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

#include <cult/types.hxx>
#include <cult/containers/set.hxx>
#include <cult/containers/vector.hxx>


#include <cstdio> // std::remove

using namespace Cult::Types;

//
//
typedef Cult::Containers::Set<NarrowString> WarningSet;

//
//
typedef Cult::Containers::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_;
  Boolean canceled_;
};

//
//
struct AutoUnlinks
{
  Void
  add (XSDFrontend::SemanticGraph::Path const& file)
  {
    unlinks_.push_back (Evptr<AutoUnlink> (new AutoUnlink (file)));
  }

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

private:
  typedef Cult::Containers::Vector<Evptr<AutoUnlink> > Unlinks;
  Unlinks unlinks_;
};

#endif // XSD_HXX