Home Libraries Author Links

loggeraids.hpp

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the SysToMath C++ Libraries package (LibStmCpp).
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Tom Michaelis, SysToMath.
00018  * Portions created by the Initial Developer are Copyright (C) 2003-2006
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /******************************************************************************
00038  *                       First Release 2003-03-15
00039  ******************************************************************************/
00040 
00041 
00085 #ifndef STM_LOGGERAIDS_HPP
00086 #define STM_LOGGERAIDS_HPP
00087 
00088 
00089 // Include header files for implementation.
00090 #include <stm/impl/loggerxaids.hpp>
00091 
00092 
00093 namespace stm
00094 {
00095 
00096 
00101 
00102 
00103 class logger_base
00104 {
00105 public:
00107     enum LockingPolicy
00108     {
00109         NoLocking      = 0,  
00110         ProcessLocking = 1,  
00111         SystemLocking  = 2   
00112     };
00113 };
00114 
00115 
00116 }  // namespace stm.
00117 
00118 
00122 // Include basic_logger base class template implementation.
00123 #include <stm/impl/loggerxaids.hpp>
00124 
00125 
00126 namespace stm
00127 {
00128 
00129 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 template
00159 <
00160     class StringT,
00161     word stdIndent = 4,
00162     word lineLength = 79,
00163     word lockingPolicy = logger_base::NoLocking
00164 >
00165 class basic_logger :
00166     public logger_base,
00167     public std::basic_ostringstream
00168     <
00169         typename StringT::value_type,
00170         typename StringT::traits_type,
00171         typename StringT::allocator_type
00172     >,
00173     private local::basic_xlogger<StringT, lockingPolicy>
00174 {
00176     typedef local::basic_xlogger<StringT, lockingPolicy> impl;
00177 
00178 public:
00181     typedef basic_logger
00182     <
00183         StringT,
00184         stdIndent,
00185         lineLength,
00186         lockingPolicy
00187     > logger_type;
00188 
00191     typedef StringT string_type;
00192 
00195     typedef std::basic_ostream
00196     <
00197         typename string_type::value_type,
00198         typename string_type::traits_type
00199     >
00200     ostream_type;
00201 
00205     typedef typename impl::char_type char_type;
00206 
00207     enum
00208     {
00209         StdIndent     = stdIndent,     
00210         LineLength    = lineLength,    
00211         LockingPolicy = lockingPolicy  
00212     };
00213 
00218     enum FmtFlags
00219     {
00220         NoFlag     = impl::NoFlag,      
00221 
00222         Indent     = impl::Indent,      
00223 
00224 
00225 
00226 
00227 
00228         NoPara     = impl::NoPara,      
00229         KeepWs     = impl::KeepWs,      
00230         AutoInd    = impl::AutoInd,     
00231         ColonInd   = impl::ColonInd,    
00232         ColonTable = impl::ColonTable,  
00233         RiJust     = impl::RiJust,      
00234         RawPath    = impl::RawPath,     
00235         Single     = impl::Single       
00236     };
00237 
00240     struct Fmt : public impl::Fmt
00241     {
00243         Fmt ();
00244 
00247         Fmt
00248         (
00249             word flags,
00250             word indent = StdIndent,
00251             word length = LineLength
00252         );
00253     };
00254 
00262     struct locker : private impl::locker
00263     {
00265         typedef basic_logger
00266         <
00267             StringT,
00268             stdIndent,
00269             lineLength,
00270             lockingPolicy
00271         > logger_type;
00272 
00274         locker (const logger_type &logger);
00275 
00277         ~locker ();
00278     };
00279 
00285     basic_logger (const std::string &mutexName = std::string ());
00286 
00289     basic_logger (const logger_type &other);
00290 
00296     basic_logger
00297     (
00298         ostream_type &stream,
00299         const std::string &mutexName = std::string ()
00300     );
00301 
00307     basic_logger
00308     (
00309         ostream_type &stream,
00310         ostream_type &console,
00311         const std::string &mutexName = std::string ()
00312     );
00313 
00316     ~basic_logger ();
00317 
00320     bool hasStream () const;
00321 
00324     void setStream (ostream_type &stream);
00325 
00328     void unsetStream ();
00329 
00332     bool hasConsole () const;
00333 
00336     void setConsole (ostream_type &console);
00337 
00340     void unsetConsole ();
00341 
00348     int adjustChild ();
00349 
00361     int operator() (Fmt streamFmt = Fmt (), Fmt consoleFmt = Fmt ());
00362 
00368     int underline (int n, char_type ch = char_type ('='), dword nl = 1);
00369 
00376     int paragraph (dword nl = 1);
00377 
00381     static string_type mkPath (const string_type &str);
00382 };
00383 
00384 
00407 template
00408 <
00409     word stdIndent = 4,
00410     word lineLength = 79,
00411     bool errorConsole = false,
00412     word lockingPolicy = logger_base::NoLocking
00413 >
00414 class logger :
00415     public basic_logger<std::string, stdIndent, lineLength, lockingPolicy>
00416 {
00417 public:
00424     logger
00425     (
00426         bool enableStream = false,
00427         std::ostream &stream = errorConsole ? std::cerr : std::cout,
00428         const std::string &mutexName = std::string ()
00429     );
00430 
00437     logger
00438     (
00439         bool enableStream,
00440         const std::string &mutexName
00441     );
00442 
00448     logger
00449     (
00450         std::ostream &stream,
00451         const std::string &mutexName
00452     );
00453 
00460     logger
00461     (
00462         std::ostream &stream,
00463         bool enableConsole = false,
00464         const std::string &mutexName = std::string ()
00465     );
00466 
00472     logger
00473     (
00474         std::ostream &stream,
00475         std::ostream &console,
00476         const std::string &mutexName = std::string ()
00477     );
00478 
00481     void setConsole ();
00482 };
00483 
00484 
00485 #ifndef STM_NO_WCHAR_T
00508 template
00509 <
00510     word stdIndent = 4,
00511     word lineLength = 79,
00512     bool errorConsole = false,
00513     word lockingPolicy = logger_base::NoLocking
00514 >
00515 class wlogger :
00516     public basic_logger<std::wstring, stdIndent, lineLength, lockingPolicy>
00517 {
00518 public:
00525     wlogger
00526     (
00527         bool enableStream = false,
00528         std::wostream &stream = errorConsole ? std::wcerr : std::wcout,
00529         const std::string &mutexName = std::string ()
00530     );
00531 
00538     wlogger
00539     (
00540         bool enableStream,
00541         const std::string &mutexName
00542     );
00543 
00549     wlogger
00550     (
00551         std::ostream &stream,
00552         const std::string &mutexName
00553     );
00554 
00561     wlogger
00562     (
00563         std::wostream &stream,
00564         bool enableConsole = false,
00565         const std::string &mutexName = std::string ()
00566     );
00567 
00573     wlogger
00574     (
00575         std::wostream &stream,
00576         std::wostream &console,
00577         const std::string &mutexName = std::string ()
00578     );
00579 
00582     void setConsole ();
00583 };
00584 #endif  // STM_NO_WCHAR_T
00585 
00586 
00590 }  // namespace stm
00591 
00592 
00593 // Include inline and template implementation.
00594 #include <stm/impl/loggerxaids.hpp>
00595 
00596 
00597 #endif  // STM_LOGGERAIDS_HPP

© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).