1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef BZF_CONFIG_FILE_MANAGER_H
14 #define BZF_CONFIG_FILE_MANAGER_H
15 
16 #include <string>
17 #include "Singleton.h"
18 
19 #define CFGMGR (ConfigFileManager::instance())
20 
21 void writeBZDB(const std::string& name, void *stream);
22 void writeKEYMGR(const std::string& name, bool press, const std::string& command, void* stream);
23 
24 /**
25  Reads in the config file.
26  Opens up the file via FileManager, ships lines off to the
27  CommandManager and handles default values in BZDB,
28 */
29 
30 class ConfigFileManager : public Singleton<ConfigFileManager>
31 {
32 public:
33     /** Read a configuration file.
34      read(filename) uses FileManager to open the stream and returns
35      false if the file cannot be opened.  they all call parse().
36     */
37     bool              read(const std::string& filename);
38     /** Read a configuration file.
39      read(filename) uses FileManager to open the stream and returns
40      false if the file cannot be opened.  they all call parse().
41     */
42     void              read(std::istream&);
43 
44     /** Write out a configuration file.
45      Writes to a format that the CommandManager can understand
46     */
47     bool              write(const std::string& filename);
48 
49 
50 protected:
51     friend class Singleton<ConfigFileManager>;
52     ConfigFileManager();
53     ~ConfigFileManager();
54 
55 private:
56     // parse a config file
57     bool              parse(std::istream&);
58 
59 };
60 
61 #endif
62 
63 // Local Variables: ***
64 // mode: C++ ***
65 // tab-width: 4 ***
66 // c-basic-offset: 4 ***
67 // indent-tabs-mode: nil ***
68 // End: ***
69 // ex: shiftwidth=4 tabstop=4
70