configuration.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: configuration.h,v 1.11 1999/04/03 00:34:33 jgg Exp $
  4. /* ######################################################################
  5. Configuration Class
  6. This class provides a configuration file and command line parser
  7. for a tree-oriented configuration environment. All runtime configuration
  8. is stored in here.
  9. Each configuration name is given as a fully scoped string such as
  10. Foo::Bar
  11. And has associated with it a text string. The Configuration class only
  12. provides storage and lookup for this tree, other classes provide
  13. configuration file formats (and parsers/emitters if needed).
  14. Most things can get by quite happily with,
  15. cout << _config->Find("Foo::Bar") << endl;
  16. A special extension, support for ordered lists is provided by using the
  17. special syntax, "block::list::" the trailing :: designates the
  18. item as a list. To access the list you must use the tree function on
  19. "block::list".
  20. ##################################################################### */
  21. /*}}}*/
  22. #ifndef PKGLIB_CONFIGURATION_H
  23. #define PKGLIB_CONFIGURATION_H
  24. #ifdef __GNUG__
  25. #pragma interface "apt-pkg/configuration.h"
  26. #endif
  27. #include <string>
  28. class Configuration
  29. {
  30. struct Item
  31. {
  32. string Value;
  33. string Tag;
  34. Item *Parent;
  35. Item *Child;
  36. Item *Next;
  37. string FullTag() const;
  38. Item() : Parent(0), Child(0), Next(0) {};
  39. };
  40. Item *Root;
  41. Item *Lookup(Item *Head,const char *S,unsigned long Len,bool Create);
  42. Item *Lookup(const char *Name,bool Create);
  43. public:
  44. string Find(const char *Name,const char *Default = 0);
  45. string Find(string Name,const char *Default = 0) {return Find(Name.c_str(),Default);};
  46. string FindFile(const char *Name,const char *Default = 0);
  47. string FindDir(const char *Name,const char *Default = 0);
  48. int FindI(const char *Name,int Default = 0);
  49. int FindI(string Name,bool Default = 0) {return FindI(Name.c_str(),Default);};
  50. bool FindB(const char *Name,bool Default = false);
  51. bool FindB(string Name,bool Default = false) {return FindB(Name.c_str(),Default);};
  52. inline void Set(string Name,string Value) {Set(Name.c_str(),Value);};
  53. void Set(const char *Name,string Value);
  54. void Set(const char *Name,int Value);
  55. inline bool Exists(string Name) {return Exists(Name.c_str());};
  56. bool Exists(const char *Name);
  57. inline const Item *Tree(const char *Name) {return Lookup(Name,false);};
  58. void Dump();
  59. Configuration();
  60. };
  61. extern Configuration *_config;
  62. bool ReadConfigFile(Configuration &Conf,string File);
  63. #endif