GNU Radio 3.6.5 C++ API

gr_prefs.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 #ifndef INCLUDED_GR_PREFS_H
00023 #define INCLUDED_GR_PREFS_H
00024 
00025 #include <gr_core_api.h>
00026 #include <string>
00027 #include <gruel/thread.h>
00028 
00029 /*!
00030  * \brief Base class for representing user preferences a la windows INI files.
00031  * \ingroup misc
00032  *
00033  * The real implementation is in Python, and is accessable from C++
00034  * via the magic of SWIG directors.
00035  */
00036 
00037 class GR_CORE_API gr_prefs
00038 {
00039 public:
00040   static gr_prefs *singleton();
00041   static void set_singleton(gr_prefs *p);
00042 
00043   gr_prefs();
00044   virtual ~gr_prefs();
00045 
00046   /*!
00047    * \brief Does \p section exist?
00048    */
00049   virtual bool has_section(const std::string &section);
00050 
00051   /*!
00052    * \brief Does \p option exist?
00053    */
00054   virtual bool has_option(const std::string &section, const std::string &option);
00055 
00056   /*!
00057    * \brief If option exists return associated value; else default_val.
00058    */
00059   virtual const std::string get_string(const std::string &section,
00060                                        const std::string &option,
00061                                        const std::string &default_val);
00062 
00063   /*!
00064    * \brief If option exists and value can be converted to bool, return it; else default_val.
00065    */
00066   virtual bool get_bool(const std::string &section,
00067                         const std::string &option,
00068                         bool default_val);
00069 
00070   /*!
00071    * \brief If option exists and value can be converted to long, return it; else default_val.
00072    */
00073   virtual long get_long(const std::string &section,
00074                         const std::string &option,
00075                         long default_val);
00076 
00077   /*!
00078    * \brief If option exists and value can be converted to double, return it; else default_val.
00079    */
00080   virtual double get_double(const std::string &section,
00081                             const std::string &option,
00082                             double default_val);
00083 
00084  protected:
00085   virtual std::vector<std::string> _sys_prefs_filenames();
00086   virtual void _read_files();
00087 
00088  private:
00089   gruel::mutex d_mutex;
00090   std::string d_configs;
00091 };
00092 
00093 
00094 #endif /* INCLUDED_GR_PREFS_H */