You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
5.0 KiB
C++
145 lines
5.0 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
|
|
|
#ifndef CRYINCLUDE_TOOLS_RC_RESOURCECOMPILER_ICONFIG_H
|
|
#define CRYINCLUDE_TOOLS_RC_RESOURCECOMPILER_ICONFIG_H
|
|
#pragma once
|
|
|
|
#include "Util.h" // BIT()
|
|
#include <vector>
|
|
#include <platform.h>
|
|
|
|
class Config;
|
|
class CPropertyVars;
|
|
|
|
enum EConfigPriority : uint32_t
|
|
{
|
|
// low priorities first
|
|
|
|
eCP_PriorityLowest = BIT(0), // used internally
|
|
|
|
eCP_PriorityFile = BIT(1), // per-file settings
|
|
eCP_PriorityPreset = BIT(2), // settings from section [<preset_name>] of rc.ini
|
|
eCP_PriorityRcIni = BIT(3), // settings from rc.ini (common + per-platform)
|
|
eCP_PriorityCmdline = BIT(4), // rc.exe's command line
|
|
eCP_PriorityProperty = BIT(5), // settings from RCJob XML properties
|
|
eCP_PriorityJob = BIT(6), // per-job configuration
|
|
|
|
eCP_PriorityHighest = BIT(7), // used internally
|
|
|
|
eCP_PriorityAll = eCP_PriorityHighest + (eCP_PriorityHighest - 1) // binary OR of all possible priority values
|
|
};
|
|
|
|
|
|
class IConfigSink
|
|
{
|
|
public:
|
|
virtual ~IConfigSink()
|
|
{
|
|
}
|
|
|
|
// Arguments:
|
|
// value - can be 0 to delete a key, can be "" to set a key without value (e.g. /refresh)
|
|
virtual void SetKeyValue(EConfigPriority ePri, const char* key, const char* value) = 0;
|
|
};
|
|
|
|
|
|
/** Configuration options interface.
|
|
*/
|
|
class IConfig
|
|
: public IConfigSink
|
|
{
|
|
public:
|
|
// Delete instance of configuration class.
|
|
virtual void Release() = 0;
|
|
|
|
virtual const Config* GetInternalRepresentation() const = 0;
|
|
|
|
virtual bool HasKeyRegistered(const char* key) const = 0;
|
|
|
|
// Returns true if the config contains a key that matches 'wildcards' name.
|
|
virtual bool HasKeyMatchingWildcards(const char* wildcards) const = 0;
|
|
|
|
// Get pointer to ASCIIZ value of a key. The pointer is not modified if the key is not found.
|
|
// Returns:
|
|
// true if key found, false if not.
|
|
virtual bool GetKeyValue(const char* key, const char*& value, int ePriMask = eCP_PriorityAll) const = 0;
|
|
|
|
// Get sum of all values of a key.
|
|
// Returns:
|
|
// 0 if key is not found or has no value
|
|
virtual int GetSum(const char* key) const = 0;
|
|
|
|
// Find unknown keys in configuration.
|
|
virtual void GetUnknownKeys(std::vector<string>& unknownKeys) const = 0;
|
|
|
|
// Merge configuration.
|
|
virtual void AddConfig(const IConfig* pCfg) = 0;
|
|
|
|
virtual void Clear() = 0;
|
|
virtual uint32 ClearPriorityUsage(int ePriMask) = 0;
|
|
virtual uint32 CountPriorityUsage(int ePriMask) const = 0;
|
|
|
|
virtual void CopyToConfig(EConfigPriority ePri, IConfigSink* pDestConfig) const = 0;
|
|
|
|
virtual void CopyToPropertyVars(CPropertyVars& properties) const = 0;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Check if configuration has a key
|
|
bool HasKey(const char* key, int ePriMask = eCP_PriorityAll) const;
|
|
|
|
// Get value of a key
|
|
bool GetAsBool(const char* const key, const bool keyIsNotFoundValue, const bool emptyOrBadValue, int ePriMask = eCP_PriorityAll) const;
|
|
int GetAsInt(const char* const key, const int keyIsNotFoundValue, const int emptyOrBadValue, int ePriMask = eCP_PriorityAll) const;
|
|
float GetAsFloat(const char* const key, const float keyIsNotFoundValue, const float emptyOrBadValue, int ePriMask = eCP_PriorityAll) const;
|
|
string GetAsString(const char* const key, const char* const keyIsNotFoundValue, const char* const emptyOrBadValue, int ePriMask = eCP_PriorityAll) const;
|
|
|
|
// str - e.g. "/reduce=2 /space=tangent"
|
|
void SetFromString(EConfigPriority ePri, const char* str);
|
|
|
|
static bool IsValidNameChar(const unsigned char c)
|
|
{
|
|
return (c > ' ') && (c != '=') && (c != ';') && (c != ':') && (c != '/');
|
|
}
|
|
|
|
private:
|
|
// Get value of a key. The value (passed by reference) is not modified if
|
|
// the key is not found or the value attached to the key is empty or bad.
|
|
enum EResult
|
|
{
|
|
eResult_Success,
|
|
eResult_KeyIsNotFound,
|
|
eResult_ValueIsEmptyOrBad,
|
|
};
|
|
EResult Get(const char* key, bool& value, int ePriMask) const;
|
|
EResult Get(const char* key, int& value, int ePriMask) const;
|
|
EResult Get(const char* key, float& value, int ePriMask) const;
|
|
EResult Get(const char* key, string& value, int ePriMask) const;
|
|
};
|
|
|
|
|
|
class IConfigKeyRegistry
|
|
{
|
|
public:
|
|
virtual ~IConfigKeyRegistry()
|
|
{
|
|
}
|
|
|
|
virtual void VerifyKeyRegistration(const char* szKey) const = 0;
|
|
virtual bool HasKeyRegistered(const char* szKey) const = 0;
|
|
};
|
|
|
|
|
|
#endif // CRYINCLUDE_TOOLS_RC_RESOURCECOMPILER_ICONFIG_H
|