Commit 1c55f487 authored by Oscar Forner Martinez's avatar Oscar Forner Martinez

Merge pull request #17 from maitesin/master

Added a new file with some utils I use to be able to do a switch with strings
parents 7dbb9eed e7c303b2
......@@ -23,6 +23,7 @@
*/
#include "Config.hpp"
#include "Utils.hpp"
#include <fstream>
#include <string>
......@@ -105,91 +106,72 @@ bool Config::readConfigFile(std::string configPath)
}
}
if (key == "include")
{
readConfigFile(getRightConfigPath(value, basePath_));
}
else if (key == "name")
{
name_ = value.toLower();
}
else if (key == "version")
{
version_ = value;
}
else if (key == "info")
{
info_ = value;
}
else if (key == "priority")
{
priority_ = value.convert<int>();
}
else if (key == "freedriver")
{
value = value.toLower();
if (value == "false")
{
freedriver_ = false;
}
else if (value == "true")
{
freedriver_ = true;
}
}
else if (key == "classids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().classIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
switch(MhwdUtils::hash(std::string(key).c_str()))
{
case MhwdUtils::hash_compile_time("include"):
readConfigFile(getRightConfigPath(value, basePath_));
break;
case MhwdUtils::hash_compile_time("name"):
name_ = value.toLower();
break;
case MhwdUtils::hash_compile_time("version"):
version_ = value;
break;
case MhwdUtils::hash_compile_time("info"):
info_ = value;
break;
case MhwdUtils::hash_compile_time("priority"):
priority_ = value.convert<int>();
break;
case MhwdUtils::hash_compile_time("freedriver"):
value = value.toLower();
freedriver_ = value == "false" ? false : true;
break;
case MhwdUtils::hash_compile_time("classids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().classIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().classIDs = splitValue(value);
}
else if (key == "vendorids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().vendorIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().classIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("vendorids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().vendorIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().vendorIDs = splitValue(value);
}
else if (key == "deviceids")
{
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().deviceIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().vendorIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("deviceids"):
// Add new HardwareIDs group to vector if vector is not empty
if (!hwdIDs_.back().deviceIDs.empty())
{
Config::HardwareID hwdID;
hwdIDs_.push_back(hwdID);
}
hwdIDs_.back().deviceIDs = splitValue(value);
}
else if (key == "blacklistedclassids")
{
hwdIDs_.back().blacklistedClassIDs = splitValue(value);
}
else if (key == "blacklistedvendorids")
{
hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
}
else if (key == "blacklisteddeviceids")
{
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
}
else if (key == "mhwddepends")
{
dependencies_ = splitValue(value);
}
else if (key == "mhwdconflicts")
{
conflicts_ = splitValue(value);
hwdIDs_.back().deviceIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklistedclassids"):
hwdIDs_.back().blacklistedClassIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklistedvendorids"):
hwdIDs_.back().blacklistedVendorIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("blacklisteddeviceids"):
hwdIDs_.back().blacklistedDeviceIDs = splitValue(value);
break;
case MhwdUtils::hash_compile_time("mhwddepends"):
dependencies_ = splitValue(value);
break;
case MhwdUtils::hash_compile_time("mhwdconflicts"):
conflicts_ = splitValue(value);
break;
}
}
......
/*
* This file is part of the mhwd - Manjaro Hardware Detection project
*
* mhwd - Manjaro Hardware Detection
* Roland Singer <roland@manjaro.org>
* Łukasz Matysiak <december0123@gmail.com>
* Filipe Marques <eagle.software3@gmail.com>
* Oscar Forner Martinez <oscar.forner.martinez@gmail.com>
*
* Copyright (C) 2007 Free Software Foundation, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MHWDUTILS_HPP_
#define MHWDUTILS_HPP_
#include <string>
#include <cstdint>
namespace MhwdUtils
{
typedef std::uint64_t hash_t;
// Hardcoded values for the prime and the basis to calculate hash values.
constexpr hash_t prime = 0x100000001B3ull;
constexpr hash_t basis = 0xCBF29CE484222325ull;
constexpr hash_t hash_compile_time(char const* str, hash_t last_value = basis)
{
return *str ? hash_compile_time(str+1, (*str ^ last_value) * prime) : last_value;
}
hash_t hash(char const* str)
{
hash_t ret{basis};
while(*str){
ret ^= *str;
ret *= prime;
str++;
}
return ret;
}
}; // End namespace
#endif /* CONFIG_HPP_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment