## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csutil/verbosity.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005 by Eric Sunshine <sunshine@sunshineco.com>
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public
    00015     License along with this library; if not, write to the Free
    00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CSUTIL_VERBOSITY_H__
    00020 #define __CS_CSUTIL_VERBOSITY_H__
    00021
    00025 #include "csextern.h"
    00026 #include "iutil/verbositymanager.h"
    00027 #include "csutil/strhash.h"
    00028 #include "csutil/csstring.h"
    00029 #include "csutil/scf_implementation.h"
    00030 class csStringArray;
    00031
    00103 class CS_CRYSTALSPACE_EXPORT csVerbosityParser
    00104 {
    00105 private:
    00106   csStringHash flags;
    00107
    00108   typedef csStringFast<128> Str;
    00109   typedef bool (*SplitPredicate)(char c, size_t pos);
    00110   static bool Split(char const*, char delim, SplitPredicate, bool empty_okay,
    00111                     csStringArray&);
    00112   static Str  Join(csStringArray const&, Str delim);
    00113   static bool Error(char const* msg, char const* s, size_t pos);
    00114   static bool ParseToggle(char const*&);
    00115   static bool ParseFlag(char const*, csStringArray&, bool empty_okay);
    00116   bool TestFlag(Str name, bool& enable) const;
    00117   void Copy(csVerbosityParser const& v) { flags = v.flags; }
    00118
    00119 public:
    00134   csVerbosityParser(char const* flags = 0);
    00135
    00139   csVerbosityParser(csVerbosityParser const& v) { Copy(v); }
    00140
    00144   ~csVerbosityParser() {}
    00145
    00149   csVerbosityParser& operator=(csVerbosityParser const& v)
    00150   { Copy(v); return *this; }
    00151
    00162   void Parse(char const* flags);
    00163
    00184   bool Enabled(char const* flag = 0, bool fuzzy = true) const;
    00185
    00192   CS_DEPRECATED_METHOD
    00193   bool CheckFlag(char const* major, char const* minor) const
    00194   {
    00195     Str flag; flag << major << '.' << minor;
    00196     return Enabled(flag);
    00197   }
    00198 };
    00199
    00219 CS_CRYSTALSPACE_EXPORT csVerbosityParser csParseVerbosity (
    00220   int argc, char const* const argv[]);
    00221
    00234 CS_CRYSTALSPACE_EXPORT bool csCheckVerbosity (
    00235   int argc, char const* const argv[], char const* flag = 0, bool fuzzy = true);
    00236
    00244 CS_DEPRECATED_METHOD
    00245 CS_CRYSTALSPACE_EXPORT bool csCheckVerbosity (
    00246   int argc, char const* const argv[], char const* major, char const* minor);
    00247
    00258 class CS_CRYSTALSPACE_EXPORT csVerbosityManager :
    00259   public scfImplementation1<csVerbosityManager, iVerbosityManager>
    00260 {
    00261 private:
    00262   csVerbosityParser vp;
    00263 public:
    00264
    00270   csVerbosityManager(char const* flags = 0)
    00271     : scfImplementationType (this), vp(flags)
    00272   { }
    00274   virtual ~csVerbosityManager() { }
    00275
    00281   virtual void Parse(char const* flags) { vp.Parse(flags); }
    00282
    00294   virtual bool Enabled(char const* flag = 0, bool fuzzy = true) const
    00295   { return vp.Enabled(flag, fuzzy); }
    00296
    00303   CS_DEPRECATED_METHOD
    00304   virtual bool CheckFlag(char const* major, char const* minor) const
    00305   {
    00306     csStringFast<128> flag; flag << major << '.' << minor;
    00307     return Enabled(flag);
    00308   }
    00309 };
    00310
    00311 #endif // __CS_CSUTIL_VERBOSITY_H__