]> git.tdb.fi Git - builder.git/blob - source/architecture.h
More flexible way to manage filename patterns
[builder.git] / source / architecture.h
1 #ifndef ARCHITECTURE_H_
2 #define ARCHITECTURE_H_
3
4 #include <typeinfo>
5 #include <msp/datafile/loader.h>
6 #include "buildinfo.h"
7 #include "pattern.h"
8
9 class Builder;
10
11 /**
12 Stores information about an architecture.  This includes CPU type, model and
13 bitness and operating system.
14 */
15 class Architecture
16 {
17 public:
18         class Loader: public Msp::DataFile::ObjectLoader<Architecture>
19         {
20         public:
21                 Loader(Architecture &);
22         };
23
24         typedef std::list<Pattern> PatternList;
25
26 private:
27         Builder &builder;
28         std::string type;
29         std::string cpu;
30         std::string fpu;
31         std::string system;
32         unsigned bits;
33         std::string toolchain;
34         std::string name;
35         bool native;
36         std::string cross_prefix;
37         std::map<std::string, PatternList> filename_patterns;
38
39 public:
40         Architecture(Builder &b, const std::string &spec);
41
42         const std::string &get_type() const { return type; }
43         const std::string &get_name() const { return name; }
44         const std::string &get_system() const { return system; }
45         unsigned get_bits() const { return bits; }
46         const std::string &get_cpu() const { return cpu; }
47         const std::string &get_fpu() const { return fpu; }
48         const std::string &get_toolchain() const { return toolchain; }
49         bool match_name(const std::string &) const;
50         std::string best_match(const std::vector<std::string> &) const;
51         bool is_native() const { return native; }
52         bool is_cross() const { return !cross_prefix.empty(); }
53
54         const std::string &get_cross_prefix() const { return cross_prefix; }
55
56         template<typename T>
57         const PatternList &get_patterns() const;
58
59         template<typename T>
60         std::string create_filename(const std::string &) const;
61
62 private:
63         template<typename T>
64         void add_pattern(const std::string &);
65
66 private:
67         static void resolve_aliases(std::vector<std::string> &);
68         void parse_specification(const std::string &);
69 };
70
71 template<typename T>
72 inline const Architecture::PatternList &Architecture::get_patterns() const
73 {
74         std::map<std::string, PatternList>::const_iterator i = filename_patterns.find(typeid(T).name());
75         if(i!=filename_patterns.end())
76                 return i->second;
77
78         static PatternList empty;
79         return empty;
80 }
81
82 template<typename T>
83 inline std::string Architecture::create_filename(const std::string &base) const
84 {
85         const PatternList &patterns = get_patterns<T>();
86         return patterns.empty() ? base : patterns.front().apply(base);
87 }
88
89 #endif