configuration.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: configuration.h,v 1.7 1998/10/30 07:53:44 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. ##################################################################### */
  17. /*}}}*/
  18. // Header section: pkglib
  19. #ifndef PKGLIB_CONFIGURATION_H
  20. #define PKGLIB_CONFIGURATION_H
  21. #ifdef __GNUG__
  22. #pragma interface "apt-pkg/configuration.h"
  23. #endif
  24. #include <string>
  25. class Configuration
  26. {
  27. struct Item
  28. {
  29. string Value;
  30. string Tag;
  31. Item *Parent;
  32. Item *Child;
  33. Item *Next;
  34. string FullTag() const;
  35. Item() : Child(0), Next(0) {};
  36. };
  37. Item *Root;
  38. Item *Lookup(Item *Head,const char *S,unsigned long Len,bool Create);
  39. Item *Lookup(const char *Name,bool Create);
  40. public:
  41. string Find(const char *Name,const char *Default = 0);
  42. string FindFile(const char *Name,const char *Default = 0);
  43. string FindDir(const char *Name,const char *Default = 0);
  44. int FindI(const char *Name,int Default = 0);
  45. bool FindB(const char *Name,bool Default = false);
  46. inline void Set(string Name,string Value) {Set(Name.c_str(),Value);};
  47. void Set(const char *Name,string Value);
  48. void Set(const char *Name,int Value);
  49. inline bool Exists(string Name) {return Exists(Name.c_str());};
  50. bool Exists(const char *Name);
  51. inline const Item *Tree(const char *Name) {return Lookup(Name,false);};
  52. void Dump();
  53. Configuration();
  54. };
  55. extern Configuration *_config;
  56. bool ReadConfigFile(Configuration &Conf,string File);
  57. #endif