2002-11-03 17:26:12 +01:00
|
|
|
/*
|
2003-09-26 16:13:15 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
* You may obtain a copy of the Licence at
|
|
|
|
* http://www.gnu.org/licences/lgpl.html
|
|
|
|
*
|
|
|
|
* As a special exception this file can also be included in modules
|
|
|
|
* with other source code as long as that source code has been
|
|
|
|
* released under an Open Source Initiative certificed licence.
|
|
|
|
* More information about OSI certification can be found at:
|
|
|
|
* http://www.opensource.org
|
|
|
|
*
|
|
|
|
* This module 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 Lesser General Public Licence for more details.
|
|
|
|
*
|
|
|
|
* This module was created by members of the firebird development
|
|
|
|
* team. All individual contributions remain the Copyright (C) of
|
|
|
|
* those individuals and all rights are reserved. Contributors to
|
|
|
|
* this file are either listed below or can be obtained from a CVS
|
|
|
|
* history command.
|
2002-11-03 17:26:12 +01:00
|
|
|
*
|
2003-09-26 16:13:15 +02:00
|
|
|
* Created by: Mark O'Donohue <skywalker@users.sourceforge.net>
|
2002-11-03 17:26:12 +01:00
|
|
|
*
|
2003-09-26 16:13:15 +02:00
|
|
|
* Contributor(s):
|
2002-11-03 17:26:12 +01:00
|
|
|
*/
|
|
|
|
|
2004-03-18 06:56:06 +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"
|
2002-11-03 17:26:12 +01:00
|
|
|
#include "fb_string.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
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-11-29 11:07:43 +01:00
|
|
|
|
2004-03-14 14:14:58 +01:00
|
|
|
typedef Firebird::SortedObjectsArray <Parameter,
|
|
|
|
Firebird::InlineStorage<Parameter *, 100>,
|
2004-11-29 11:07:43 +01:00
|
|
|
string, Firebird::FirstPointerKey<Parameter> > mymap_t;
|
2002-11-03 17:26:12 +01:00
|
|
|
|
|
|
|
public:
|
2004-08-30 20:11:08 +02:00
|
|
|
ConfigFile(MemoryPool& p, bool ExceptionOnError)
|
2004-03-14 14:14:58 +01:00
|
|
|
: AutoStorage(p), isLoadedFlg(false),
|
2004-08-30 20:11:08 +02:00
|
|
|
fExceptionOnError(ExceptionOnError), parameters(getPool()) {}
|
|
|
|
explicit ConfigFile(bool ExceptionOnError)
|
2004-03-14 14:14:58 +01:00
|
|
|
: AutoStorage(), isLoadedFlg(false),
|
2004-08-30 20:11:08 +02:00
|
|
|
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;
|
2004-08-30 20:11:08 +02:00
|
|
|
bool fExceptionOnError;
|
2002-11-03 17:26:12 +01:00
|
|
|
mymap_t parameters;
|
|
|
|
};
|
|
|
|
|
2004-03-18 06:56:06 +01:00
|
|
|
#endif // CONFIG_CONFIG_FILE_H
|