I have a generated class, that provides access to a database and maps the field values for each row with the field names for that column. We use it to avoid typing mistakes in the queries and write code like for(auto& entity: db.table1) { doSomething(entity.field1()); }
.
However, each CPP file that includes this header starts to compile slow, generates a big object file (~14 MB) and causes very long linker times (GCC on Windows).
Here's a very shortened version of this class structure. Is there any way to speed up my linker times?
// MyDatabase.hxx
#include <vector>
#include <memory>
// this template is a generic header
template <class TableData> class Table {
public:
TableData getFirstRowFromDatabase() {return m_rows.begin();}
// following many, very complex member functions
std::vector<TableData> m_rows;
};
// this class declaration is generated by a program by parsing the SQL schema
class MyDatabase {
public:
// Data structure holding the fields of a table and relationship to database names
class Data1 /*: public BaseEntity */ {
public:
int i;
struct TEXT {
const char* i()const {return "i";}
};
// bool readFromDatabase() overrides {...}
};
class Data2 {
public:
double d;
// ...
};
// ... many more Data definitions here ...
Table<Data1> m_data1;
Table<Data2> m_data2;
// ... many table members here
};
// try to avoid an instance of MyDatabase in any other CPP file
std::shared_ptr<MyDatabase> openDatabase();
// MyDatabase.cpp
// #include "MyDatabase.h"
std::shared_ptr<MyDatabase> openDatabase() {
return std::make_shared<MyDatabase>();
}
// main.cpp
// #include "MyDatabase.h"
int main() {
auto table = openDatabase();
}
[edit] changed title, thank you.