Back to index

nordugrid-arc-nox  1.1.0~rc6
configcore.h
Go to the documentation of this file.
00001 
00004 #ifndef ARCLIB_CONFIGCORE
00005 #define ARCLIB_CONFIGCORE
00006 
00007 #include <iostream>
00008 #include <list>
00009 #include <map>
00010 #include <string>
00011 
00012 #include <arc/Logger.h>
00013 
00014 
00015 namespace ARex {
00016 
00017 extern Arc::Logger ConfigLogger;
00018 
00022 class ConfigError : public std::exception {
00023        private:
00024               std::string message_;
00025 
00026        public:
00030               ConfigError(std::string message) : message_(message) {};
00031               virtual ~ConfigError(void) throw() {};
00032               std::string& what(void) { return message_; };
00033 };
00034 
00035 
00036 class Option {
00037        public:
00038               Option(const std::string& attr, const std::string& value);
00039               Option(const std::string& attr, const std::string& value,
00040                         const std::map<std::string, std::string>& suboptions);
00041               ~Option();
00042               void AddSubOption(const std::string& attr, const std::string& value);
00043               std::string FindSubOptionValue(const std::string& attr) const;
00044               const std::string& GetAttr() const;
00045               const std::string& GetValue() const;
00046               const std::map<std::string, std::string>& GetSubOptions() const;
00047        private:
00048               std::string attr;
00049               std::string value;
00050               std::map<std::string, std::string> suboptions;
00051 };
00052 
00053 
00054 class ConfGrp {
00055        public:
00056               ConfGrp(const std::string& section);
00057               ConfGrp(const std::string& section, const std::string& id);
00058               ConfGrp(const std::string& section, const std::string& id,
00059                       const std::list<Option>& options);
00060               void AddOption(const Option& opt);
00061               std::list<Option> FindOption(const std::string& attr) const;
00062               std::list<std::string> FindOptionValue(const std::string& attr) const;
00063               const std::string& GetSection() const;
00064               const std::string& GetID() const;
00065               const std::list<Option>& GetOptions() const;
00066        private:
00067               std::string section;
00068               std::string id;
00069               std::list<Option> options;
00070 };
00071 
00072 
00074 class Config {
00075        public:
00076               Config();
00077 
00078               ~Config();
00079 
00080               void AddConfGrp(const ConfGrp& confgrp);
00081 
00082               /* finds the LAST config group that matches in the section/id. */
00083               const ConfGrp& FindConfGrp(const std::string& section,
00084                                                            const std::string& id) const;
00085 
00087               const std::list<ConfGrp>& GetConfigs() const;
00088 
00090               std::list<std::string> ConfValue(const std::string& path) const;
00091 
00096               std::string FirstConfValue(const std::string& path) const;
00097 
00098        private:
00099               std::list<ConfGrp> configs;
00100 };
00101 
00102 
00104 Config ReadConfig(std::istream& is);
00105 
00106 
00108 Config ReadConfig(const std::string& filename);
00109 
00110 }
00111 
00112 #endif //  ARCLIB_CONFIGCORE