CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 class csStringArray;
00030 
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 : public iVerbosityManager
00259 {
00260 private:
00261   csVerbosityParser vp;
00262 public:
00263   SCF_DECLARE_IBASE;
00264 
00270   csVerbosityManager(char const* flags = 0) : vp(flags)
00271   { SCF_CONSTRUCT_IBASE(0); }
00273   virtual ~csVerbosityManager() { SCF_DESTRUCT_IBASE(); }
00274 
00280   virtual void Parse(char const* flags) { vp.Parse(flags); }
00281 
00293   virtual bool Enabled(char const* flag = 0, bool fuzzy = true) const
00294   { return vp.Enabled(flag, fuzzy); }
00295 
00302   CS_DEPRECATED_METHOD
00303   virtual bool CheckFlag(char const* major, char const* minor) const
00304   {
00305     csStringFast<128> flag; flag << major << '.' << minor;
00306     return Enabled(flag);
00307   }
00308 };
00309 
00310 #endif // __CS_CSUTIL_VERBOSITY_H__

Generated for Crystal Space by doxygen 1.4.4