]> git.tdb.fi Git - builder.git/blob - source/architecture.h
Remove most container typedefs and refactor others
[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 private:
25         Builder &builder;
26         std::string type;
27         std::string cpu;
28         std::string fpu;
29         std::string system;
30         unsigned bits;
31         std::string toolchain;
32         std::string name;
33         bool native;
34         std::string cross_prefix;
35         std::map<std::string, std::list<Pattern>> filename_patterns;
36
37 public:
38         Architecture(Builder &b, const std::string &spec);
39
40         const std::string &get_type() const { return type; }
41         const std::string &get_name() const { return name; }
42         const std::string &get_system() const { return system; }
43         unsigned get_bits() const { return bits; }
44         const std::string &get_cpu() const { return cpu; }
45         const std::string &get_fpu() const { return fpu; }
46         const std::string &get_toolchain() const { return toolchain; }
47         bool match_name(const std::string &) const;
48         std::string best_match(const std::vector<std::string> &) const;
49         bool is_native() const { return native; }
50         bool is_cross() const { return !cross_prefix.empty(); }
51
52         const std::string &get_cross_prefix() const { return cross_prefix; }
53
54         template<typename T>
55         const std::list<Pattern> &get_patterns() const;
56
57         template<typename T>
58         std::string create_filename(const std::string &) const;
59
60 private:
61         template<typename T>
62         void add_pattern(const std::string &);
63
64 private:
65         static void resolve_aliases(std::vector<std::string> &);
66         void parse_specification(const std::string &);
67 };
68
69 template<typename T>
70 inline const std::list<Pattern> &Architecture::get_patterns() const
71 {
72         auto i = filename_patterns.find(typeid(T).name());
73         if(i!=filename_patterns.end())
74                 return i->second;
75
76         static std::list<Pattern> empty;
77         return empty;
78 }
79
80 template<typename T>
81 inline std::string Architecture::create_filename(const std::string &base) const
82 {
83         const std::list<Pattern> &patterns = get_patterns<T>();
84         return patterns.empty() ? base : patterns.front().apply(base);
85 }
86
87 #endif