]> git.tdb.fi Git - libs/datafile.git/blob - tool/compiler.h
Add a compile mode to mspdatatool
[libs/datafile.git] / tool / compiler.h
1 /* $Id$
2
3 This file is part of libmspdatafile
4 Copyright © 2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef TOOL_COMPILER_H_
9 #define TOOL_COMPILER_H_
10
11 #include <msp/datafile/loader.h>
12 #include <msp/datafile/statement.h>
13 #include <msp/datafile/writer.h>
14 #include <msp/fs/path.h>
15
16 class Compiler: public Msp::DataFile::Loader
17 {
18         friend class File;
19         friend class ForEach;
20
21 private:
22         Msp::DataFile::Writer &writer;
23
24 public:
25         Compiler(Msp::DataFile::Writer &);
26 private:
27         void file(const std::string &);
28         void for_each(const std::vector<std::string> &);
29         void write(const Msp::DataFile::Statement &);
30
31         bool process_statement(const Msp::FS::Path &, Msp::DataFile::Statement &);
32         void process_file(const Msp::FS::Path &, const std::list<Msp::DataFile::Statement> &);
33         void process_file(const Msp::FS::Path &);
34 };
35
36 class File: public Msp::DataFile::Loader
37 {
38 private:
39         Compiler &compiler;
40         Msp::FS::Path filename;
41         std::list<Msp::DataFile::Statement> write_st;
42
43 public:
44         File(Compiler &, const Msp::FS::Path &);
45 private:
46         virtual void finish();
47
48         void write(const Msp::DataFile::Statement &);
49 };
50
51 class ForEach: public Msp::DataFile::Loader
52 {
53 private:
54         Compiler &compiler;
55         Msp::FS::Path base;
56         std::list<std::string> patterns;
57         std::list<std::string> excludes;
58         std::list<Msp::DataFile::Statement> write_st;
59
60 public:
61         ForEach(Compiler &, const Msp::FS::Path &, const std::list<std::string> &);
62 private:
63         virtual void finish();
64
65         void exclude(const std::string &);
66         void pattern(const std::string &);
67         void write(const Msp::DataFile::Statement &);
68 };
69
70 #endif