TMemStatHelpers.h

Go to the documentation of this file.
00001 // @(#)root/memstat:$Id: TMemStatHelpers.h 32768 2010-03-25 15:34:18Z pcanal $
00002 // Author: Anar Manafov (A.Manafov@gsi.de) 2008-03-02
00003 
00004 /*************************************************************************
00005 * Copyright (C) 1995-2010, Rene Brun and Fons Rademakers.               *
00006 * All rights reserved.                                                  *
00007 *                                                                       *
00008 * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010 *************************************************************************/
00011 #ifndef ROOT_TMemStatHelpers
00012 #define ROOT_TMemStatHelpers
00013 
00014 // ROOT
00015 #include "TString.h"
00016 #include "TObjString.h"
00017 #include "TCollection.h"
00018 // STD
00019 #include <string>
00020 #include <functional>
00021 #include <algorithm>
00022 #include <cctype>
00023 
00024 
00025 class TObject;
00026 
00027 namespace memstat {
00028    std::string dig2bytes(Long64_t bytes);
00029 
00030 //______________________________________________________________________________
00031    struct SFind_t : std::binary_function<TObject*, TString, bool> {
00032       bool operator()(TObject *_Obj, const TString &_ToFind) const {
00033          TObjString *str(dynamic_cast<TObjString*>(_Obj));
00034          if(!str)
00035             return false;
00036          return !str->String().CompareTo(_ToFind);
00037       }
00038    };
00039 
00040 //______________________________________________________________________________
00041    template<class T>
00042    Int_t find_string(const T &_Container,  const TString &_ToFind)
00043    {
00044       // This function retuns an index in _Container of found element.
00045       // Returns -1 if there was no element found.
00046 
00047       typedef TIterCategory<T> iterator_t;
00048 
00049       iterator_t iter(&_Container);
00050       iterator_t found(
00051          std::find_if(iter.Begin(), iterator_t::End(), bind2nd(SFind_t(), _ToFind))
00052       );
00053       return ((!(*found)) ? -1 : std::distance(iter.Begin(), found));
00054    }
00055 
00056 //______________________________________________________________________________
00057 // HACK: because of the bug in gcc 3.3 we need to use this nasty ToLower and ToUpper instead of direct calls of tolower (tolower.. is inline in this version of std lib)...
00058    struct ToLower_t {
00059       char operator()(char c) const {
00060          return std::tolower(c);
00061       }
00062    };
00063 
00064 }
00065 #endif

Generated on Tue Jul 5 14:27:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1