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

166 lines
4.6 KiB
C
Raw Normal View History

/*
* PROGRAM: Client/Server Common Code
* MODULE: dir_list.h
* DESCRIPTION: Directory listing config file operation
*
* The contents of this file are subject to the Interbase 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.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Created by: Alex Peshkov <AlexPeshkov@users.sourceforge.net>
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#ifndef CONFIG_DIR_LIST_H
#define CONFIG_DIR_LIST_H
2003-05-01 14:20:40 +02:00
#include "fb_types.h"
#include "../common/classes/fb_string.h"
2003-05-05 14:26:37 +02:00
#include "../common/config/config_file.h"
2003-05-01 14:20:40 +02:00
2004-03-14 14:14:58 +01:00
namespace Firebird {
2003-03-17 19:01:17 +01:00
//
// This class is used internally by DirectoryList
// to store single path in format of pre-parsed
// elements of that path & perform basic operations
// with this path representation.
// Because of it's internal nature it has only
// internally required subset of possible operators.
//
2004-03-14 14:14:58 +01:00
class ParsedPath : public ObjectsArray<PathName>
{
typedef ObjectsArray<PathName> inherited;
public:
2004-03-14 14:14:58 +01:00
explicit ParsedPath(MemoryPool& p) : ObjectsArray<PathName>(p) { }
ParsedPath(MemoryPool& p, const PathName& path)
2004-03-14 14:14:58 +01:00
: ObjectsArray<PathName>(p)
{
parse(path);
}
ParsedPath() : ObjectsArray<PathName>() { }
2004-03-14 14:14:58 +01:00
explicit ParsedPath(const PathName& path)
: ObjectsArray<PathName>()
{
parse(path);
}
// Take new path inside
void parse(const PathName& path);
2003-03-17 19:01:17 +01:00
// Convert internal representation to traditional one
2004-03-14 14:14:58 +01:00
operator PathName() const;
2003-03-17 19:01:17 +01:00
// Compare with path given by constant
2004-03-14 14:14:58 +01:00
bool operator==(const char* path) const
{
return PathName(*this) == path;
}
2003-03-17 19:01:17 +01:00
// Check, whether pPath lies inside directory tree,
// specified by *this ParsedPath. Also checks against
// possible symbolic links.
2004-03-14 14:14:58 +01:00
bool contains(const ParsedPath& pPath) const;
// Returns path, containing elements from 0 to n-1
PathName subPath(int n) const;
};
2004-03-14 14:14:58 +01:00
class DirectoryList : public ObjectsArray<ParsedPath> {
private:
2004-03-14 14:14:58 +01:00
typedef ObjectsArray<ParsedPath> inherited;
// ListMode must be changed together with ListKeys in dir_list.cpp
enum ListMode {NotInitialized = -1,
2003-05-01 14:20:40 +02:00
None = 0, Restrict = 1, Full = 2, SimpleList = 3};
2004-03-14 14:14:58 +01:00
ListMode mode;
// Check, whether Value begins with Key,
// followed by any character from Next.
// If Next is empty, Value shoult exactly match Key.
// If Key found, sets Mode to KeyMode and returns true.
2004-03-14 14:14:58 +01:00
bool keyword(const ListMode keyMode, PathName& value,
PathName key, PathName next);
protected:
2004-03-14 14:14:58 +01:00
// Clear allocated memory and reinitialize
void clear(void) {
((inherited*)this)->clear();
mode = NotInitialized;
}
2003-03-17 19:01:17 +01:00
// Used for various configuration parameters -
// returns parameter PathName from Config Manager.
2004-03-14 14:14:58 +01:00
virtual const PathName getConfigString(void) const = 0;
2003-05-01 14:20:40 +02:00
// Initialize loads data from Config Manager.
// With simple mutex add-on may be easily used to
// load them dynamically. Now called locally
// when IsPathInList() invoked first time.
2004-03-14 14:14:58 +01:00
void initialize(bool simple_mode = false);
public:
2004-03-14 14:14:58 +01:00
explicit DirectoryList(MemoryPool& p)
: ObjectsArray<ParsedPath>(p), mode(NotInitialized) { }
DirectoryList()
: ObjectsArray<ParsedPath>(), mode(NotInitialized) { }
virtual ~DirectoryList() {clear();}
// Check, whether Path is inside this DirectoryList
2004-03-14 14:14:58 +01:00
bool isPathInList(const PathName& path) const;
// Search for file Name in all direcories of DirectoryList.
// If found, return full path to it in Path.
// Otherwise Path = Name.
bool expandFileName(PathName& path,
const PathName& name) const;
// Use first directory in this directory list
// to build default full name for a file
bool defaultName(PathName& path,
const PathName& name) const;
};
2003-05-01 14:20:40 +02:00
2004-03-14 14:14:58 +01:00
class TempDirectoryList : protected DirectoryList {
typedef DirectoryList inherited;
2003-05-01 14:20:40 +02:00
public:
2004-03-14 14:14:58 +01:00
// directory list item(s)
typedef Pair<Left<PathName, size_t> > Item;
typedef ObjectsArray<Item> Items;
2003-05-01 14:20:40 +02:00
// public functions
2004-03-14 14:14:58 +01:00
const Item& operator[](size_t i) const
{
return items[i];
}
int getCount() const
2004-03-14 14:14:58 +01:00
{
return items.getCount();
}
2003-05-01 14:20:40 +02:00
2004-03-14 14:14:58 +01:00
explicit TempDirectoryList(MemoryPool& p)
: DirectoryList(p), items(p)
{
initTemp();
}
TempDirectoryList()
{
initTemp();
}
~TempDirectoryList() {
items.clear();
}
2003-05-01 14:20:40 +02:00
private:
// implementation of the inherited function
2004-03-14 14:14:58 +01:00
const PathName getConfigString() const;
2003-05-01 14:20:40 +02:00
// private data
2004-03-14 14:14:58 +01:00
Items items;
// load items from DirectoryList
2004-03-15 20:35:00 +01:00
void initTemp();
2003-05-01 14:20:40 +02:00
};
2004-03-14 14:14:58 +01:00
} //namespace Firebird
#endif // CONFIG_DIR_LIST_H