8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-01 22:40:39 +01:00
firebird-mirror/src/common/config/config_file.h

96 lines
3.2 KiB
C
Raw Normal View History

2002-11-03 17:26:12 +01:00
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
2002-11-03 17:26:12 +01:00
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
2002-11-03 17:26:12 +01:00
*
* The Original Code was created by Dmitry Yemanov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2002 Dmitry Yemanov <dimitr@users.sf.net>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
2002-11-03 17:26:12 +01:00
*/
#ifndef CONFIG_CONFIG_FILE_H
#define CONFIG_CONFIG_FILE_H
2002-11-03 17:26:12 +01:00
#include <functional>
#include <map>
2003-01-30 14:26:16 +01:00
#include "../../common/classes/alloc.h"
2004-03-14 14:14:58 +01:00
#include "../../common/classes/fb_pair.h"
#include "../../common/classes/objects_array.h"
#include "../common/classes/fb_string.h"
2002-11-03 17:26:12 +01:00
/**
Since the original (isc.cpp) code wasn't able to provide powerful and
easy-to-use abilities to work with complex configurations, a decision
has been made to create a completely new one.
The below class implements generic file abstraction for new configuration
manager. It allows "value-by-key" retrieval based on plain text files. Both
keys and values are just strings that may be handled case-sensitively or
case-insensitively, depending on host OS. The configuration file is loaded
on demand, its current status can be checked with isLoaded() member function.
All leading and trailing spaces are ignored. Comments (follow after a
hash-mark) are ignored as well.
Now this implementation is used by generic configuration manager
(common/config/config.cpp) and server-side alias manager (jrd/db_alias.cpp).
**/
2004-03-14 14:14:58 +01:00
class ConfigFile : public Firebird::AutoStorage
2002-11-03 17:26:12 +01:00
{
2004-02-08 18:08:34 +01:00
// config_file works with OS case-sensitivity
typedef Firebird::PathName string;
2002-11-03 17:26:12 +01:00
2004-03-14 14:14:58 +01:00
typedef Firebird::Pair<Firebird::Full<string, string> > Parameter;
2004-03-14 14:14:58 +01:00
typedef Firebird::SortedObjectsArray <Parameter,
Firebird::InlineStorage<Parameter *, 100>,
string, Firebird::FirstPointerKey<Parameter> > mymap_t;
2002-11-03 17:26:12 +01:00
public:
ConfigFile(MemoryPool& p, bool ExceptionOnError)
2004-03-14 14:14:58 +01:00
: AutoStorage(p), isLoadedFlg(false),
fExceptionOnError(ExceptionOnError), parameters(getPool()) {}
explicit ConfigFile(bool ExceptionOnError)
2004-03-14 14:14:58 +01:00
: AutoStorage(), isLoadedFlg(false),
fExceptionOnError(ExceptionOnError), parameters(getPool()) {}
2002-11-03 17:26:12 +01:00
// configuration file management
const string getConfigFile() { return configFile; }
void setConfigFile(const string& newFile) { configFile = newFile; }
bool isLoaded() const { return isLoadedFlg; }
void loadConfig();
void checkLoadConfig();
// key and value management
bool doesKeyExist(const string&);
string getString(const string&);
// utilities
static void stripComments(string&);
static string parseKeyFrom(const string&, string::size_type&);
static string parseValueFrom(string, string::size_type);
private:
string configFile;
bool isLoadedFlg;
bool fExceptionOnError;
2002-11-03 17:26:12 +01:00
mymap_t parameters;
};
#endif // CONFIG_CONFIG_FILE_H