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