mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 06:05:01 +02:00
parent
f8d7f7799e
commit
e7184225f3
@ -161,21 +161,24 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary
|
|||||||
if (!instance)
|
if (!instance)
|
||||||
instance = type->Instantiate();
|
instance = type->Instantiate();
|
||||||
|
|
||||||
for (int i = 0; i < type->GetFieldCount(); i++) {
|
BOOST_FOREACH(const Dictionary::Pair& kv, input) {
|
||||||
Field field = type->GetFieldInfo(i);
|
if (kv.first.IsEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int fid = type->GetFieldId(kv.first);
|
||||||
|
|
||||||
|
if (fid < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Field field = type->GetFieldInfo(fid);
|
||||||
|
|
||||||
if ((field.Attributes & attributeTypes) == 0)
|
if ((field.Attributes & attributeTypes) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Value value = input->Get(field.Name);
|
|
||||||
|
|
||||||
if (value.IsEmpty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
instance->SetField(i, Deserialize(value, attributeTypes));
|
instance->SetField(fid, Deserialize(kv.second, attributeTypes));
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
instance->SetField(i, Empty);
|
instance->SetField(fid, Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,12 +705,18 @@ String Utility::GetThreadName(void)
|
|||||||
return *name;
|
return *name;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long Utility::SDBM(const String& str)
|
unsigned long Utility::SDBM(const String& str, size_t len)
|
||||||
{
|
{
|
||||||
unsigned long hash = 0;
|
unsigned long hash = 0;
|
||||||
|
size_t current = 0;
|
||||||
|
|
||||||
BOOST_FOREACH(char c, str) {
|
BOOST_FOREACH(char c, str) {
|
||||||
|
if (current >= len)
|
||||||
|
break;
|
||||||
|
|
||||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||||
|
|
||||||
|
current++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
|
@ -102,7 +102,7 @@ public:
|
|||||||
static void SetThreadName(const String& name, bool os = true);
|
static void SetThreadName(const String& name, bool os = true);
|
||||||
static String GetThreadName(void);
|
static String GetThreadName(void);
|
||||||
|
|
||||||
static unsigned long SDBM(const String& str);
|
static unsigned long SDBM(const String& str, size_t len = String::NPos);
|
||||||
|
|
||||||
static int CompareVersion(const String& v1, const String& v2);
|
static int CompareVersion(const String& v1, const String& v2);
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -77,6 +79,27 @@ void ClassCompiler::HandleCode(const std::string& code, const ClassDebugInfo& lo
|
|||||||
std::cout << code << std::endl;
|
std::cout << code << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long ClassCompiler::SDBM(const std::string& str, size_t len = std::string::npos)
|
||||||
|
{
|
||||||
|
unsigned long hash = 0;
|
||||||
|
size_t current = 0;
|
||||||
|
|
||||||
|
std::string::const_iterator it;
|
||||||
|
|
||||||
|
for (it = str.begin(); it != str.end(); it++) {
|
||||||
|
if (current >= len)
|
||||||
|
break;
|
||||||
|
|
||||||
|
char c = *it;
|
||||||
|
|
||||||
|
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||||
|
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
||||||
{
|
{
|
||||||
std::vector<Field>::const_iterator it;
|
std::vector<Field>::const_iterator it;
|
||||||
@ -136,11 +159,47 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
|||||||
|
|
||||||
std::cout << ";" << std::endl << std::endl;
|
std::cout << ";" << std::endl << std::endl;
|
||||||
|
|
||||||
int num = 0;
|
std::map<int, std::vector<std::pair<int, std::string> > > jumptable;
|
||||||
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
|
||||||
std::cout << "\t\t" << "if (name == \"" << it->Name << "\")" << std::endl
|
int hlen = 0, collisions = 0;
|
||||||
<< "\t\t\t" << "return offset + " << num << ";" << std::endl;
|
|
||||||
num++;
|
do {
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
hlen++;
|
||||||
|
jumptable.clear();
|
||||||
|
collisions = 0;
|
||||||
|
|
||||||
|
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
||||||
|
int hash = static_cast<int>(SDBM(it->Name, hlen));
|
||||||
|
jumptable[hash].push_back(std::make_pair(num, it->Name));
|
||||||
|
num++;
|
||||||
|
|
||||||
|
if (jumptable[hash].size() > 1)
|
||||||
|
collisions++;
|
||||||
|
}
|
||||||
|
} while (collisions >= 5 && hlen < 8);
|
||||||
|
|
||||||
|
if (!klass.Fields.empty()) {
|
||||||
|
std::cout << "\t\tswitch (static_cast<int>(Utility::SDBM(name, " << hlen << "))) {" << std::endl;
|
||||||
|
|
||||||
|
std::map<int, std::vector<std::pair<int, std::string> > >::const_iterator itj;
|
||||||
|
|
||||||
|
for (itj = jumptable.begin(); itj != jumptable.end(); itj++) {
|
||||||
|
std::cout << "\t\t\tcase " << itj->first << ":" << std::endl;
|
||||||
|
|
||||||
|
std::vector<std::pair<int, std::string> >::const_iterator itf;
|
||||||
|
|
||||||
|
for (itf = itj->second.begin(); itf != itj->second.end(); itf++) {
|
||||||
|
std::cout << "\t\t\t\t" << "if (name == \"" << itf->second << "\")" << std::endl
|
||||||
|
<< "\t\t\t\t\t" << "return offset + " << itf->first << ";" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << std::endl
|
||||||
|
<< "\t\t\t\tbreak;" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "\t\t}" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl
|
std::cout << std::endl
|
||||||
@ -178,7 +237,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
|||||||
|
|
||||||
std::cout << ") {" << std::endl;
|
std::cout << ") {" << std::endl;
|
||||||
|
|
||||||
num = 0;
|
size_t num = 0;
|
||||||
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
||||||
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
|
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
|
||||||
<< "\t\t\t\t" << "return Field(" << num << ", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
|
<< "\t\t\t\t" << "return Field(" << num << ", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
|
||||||
@ -259,7 +318,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo& locp)
|
|||||||
|
|
||||||
std::cout << ") {" << std::endl;
|
std::cout << ") {" << std::endl;
|
||||||
|
|
||||||
num = 0;
|
size_t num = 0;
|
||||||
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
|
||||||
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
|
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
|
||||||
<< "\t\t\t\t" << "Set" << it->GetFriendlyName() << "(";
|
<< "\t\t\t\t" << "Set" << it->GetFriendlyName() << "(";
|
||||||
@ -417,7 +476,8 @@ void ClassCompiler::CompileStream(const std::string& path, std::istream *stream)
|
|||||||
<< "#include \"base/debug.h\"" << std::endl
|
<< "#include \"base/debug.h\"" << std::endl
|
||||||
<< "#include \"base/value.h\"" << std::endl
|
<< "#include \"base/value.h\"" << std::endl
|
||||||
<< "#include \"base/array.h\"" << std::endl
|
<< "#include \"base/array.h\"" << std::endl
|
||||||
<< "#include \"base/dictionary.h\"" << std::endl << std::endl
|
<< "#include \"base/dictionary.h\"" << std::endl
|
||||||
|
<< "#include \"base/utility.h\"" << std::endl << std::endl
|
||||||
<< "#ifdef _MSC_VER" << std::endl
|
<< "#ifdef _MSC_VER" << std::endl
|
||||||
<< "#pragma warning( push )" << std::endl
|
<< "#pragma warning( push )" << std::endl
|
||||||
<< "#pragma warning( disable : 4244 )" << std::endl
|
<< "#pragma warning( disable : 4244 )" << std::endl
|
||||||
|
@ -142,6 +142,8 @@ private:
|
|||||||
std::string m_Path;
|
std::string m_Path;
|
||||||
std::istream *m_Input;
|
std::istream *m_Input;
|
||||||
void *m_Scanner;
|
void *m_Scanner;
|
||||||
|
|
||||||
|
static unsigned long SDBM(const std::string& str, size_t len);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user