| Line |
Branch |
Exec |
Source |
| 1 |
|
|
|
| 2 |
|
|
#include "MsXpS/libXpertMassCore/jsclassregistrar.h" |
| 3 |
|
|
|
| 4 |
|
|
namespace MsXpS |
| 5 |
|
|
{ |
| 6 |
|
|
std::unordered_map<NamespaceClassnamePairAsKey, |
| 7 |
|
|
RegisterFunc, |
| 8 |
|
|
NamespaceClassnameAsKeyHash, |
| 9 |
|
|
AreNamespaceClassnamePairsEqual> & |
| 10 |
|
858 |
getNameSpaceClassNameJsConstructorRegistrarMap() |
| 11 |
|
|
{ |
| 12 |
|
858 |
static std::unordered_map<NamespaceClassnamePairAsKey, |
| 13 |
|
|
RegisterFunc, |
| 14 |
|
|
NamespaceClassnameAsKeyHash, |
| 15 |
|
|
AreNamespaceClassnamePairsEqual> |
| 16 |
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 856 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
858 |
map; |
| 17 |
|
858 |
return map; |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
void |
| 22 |
|
✗ |
registerJsConstructorForEachClassInRegistrarMap(QJSEngine *engine) |
| 23 |
|
|
{ |
| 24 |
|
✗ |
qDebug() << "Registering the constructor of the classes marked for JS."; |
| 25 |
|
|
|
| 26 |
|
✗ |
qsizetype count = getNameSpaceClassNameJsConstructorRegistrarMap().size(); |
| 27 |
|
✗ |
qDebug() << "Size of the map: count" << count; |
| 28 |
|
|
|
| 29 |
|
✗ |
for(const auto &entry : getNameSpaceClassNameJsConstructorRegistrarMap()) |
| 30 |
|
✗ |
entry.second(engine); |
| 31 |
|
✗ |
} |
| 32 |
|
|
|
| 33 |
|
|
// Note that name_space can be compounded: MsXpS::libXpertMassCore, for class name Formula, for example. |
| 34 |
|
|
void |
| 35 |
|
✗ |
registerJsConstructorForNameSpaceClassNameInRegistrarMap(const QString &name_space, |
| 36 |
|
|
const QString &class_name, |
| 37 |
|
|
QJSEngine *engine) |
| 38 |
|
|
{ |
| 39 |
|
|
// Remember, the registrar map is actually a map of map: |
| 40 |
|
|
|
| 41 |
|
|
// Key type: pair of namespace and class name |
| 42 |
|
|
// using NamespaceClassnamePairAsKey = std::pair<QString, QString>; |
| 43 |
|
|
// using RegisterFunc = std::function<void(QJSEngine *)>; |
| 44 |
|
|
// |
| 45 |
|
|
// std::unordered_map<NamespaceClassnamePairAsKey, |
| 46 |
|
|
// RegisterFunc, |
| 47 |
|
|
// NsClassKeyHash, |
| 48 |
|
|
// AreNamespaceClassnamePairAsKeyEqual> |
| 49 |
|
|
|
| 50 |
|
|
// So, first look for a pair<NamespaceClassnamePairAsKey, RegisterFunc> |
| 51 |
|
|
// having key = {name_sape, class_name}, that is, a std::pair<QString, |
| 52 |
|
|
// QString>. Once we get that map item, run the second member of the |
| 53 |
|
|
// outer map item which actually runs the functor. |
| 54 |
|
✗ |
auto it = getNameSpaceClassNameJsConstructorRegistrarMap().find({name_space, class_name}); |
| 55 |
|
✗ |
if(it != getNameSpaceClassNameJsConstructorRegistrarMap().end()) |
| 56 |
|
✗ |
it->second(engine); |
| 57 |
|
|
else |
| 58 |
|
✗ |
qWarning().noquote() << "No JS constructor registered for namespace" << name_space |
| 59 |
|
✗ |
<< "and class name" << class_name; |
| 60 |
|
✗ |
} |
| 61 |
|
|
|
| 62 |
|
|
}// namespace MsXps |
| 63 |
|
|
|