Logo ROOT  
Reference Guide
TMemStatHelpers.h
Go to the documentation of this file.
1// @(#)root/memstat:$Id$
2// Author: Anar Manafov (A.Manafov@gsi.de) 2008-03-02
3
4/*************************************************************************
5* Copyright (C) 1995-2010, Rene Brun and Fons Rademakers. *
6* All rights reserved. *
7* *
8* For the licensing terms see $ROOTSYS/LICENSE. *
9* For the list of contributors see $ROOTSYS/README/CREDITS. *
10*************************************************************************/
11#ifndef ROOT_TMemStatHelpers
12#define ROOT_TMemStatHelpers
13
14// ROOT
15#include "TString.h"
16#include "TObjString.h"
17#include "TCollection.h"
18// STD
19#include <string>
20#include <functional>
21#include <algorithm>
22#include <cctype>
23
24
25class TObject;
26
27namespace Memstat {
28 std::string dig2bytes(Long64_t bytes);
29
30//______________________________________________________________________________
31 struct SFind_t : std::binary_function<TObject*, TString, bool> {
32 bool operator()(TObject *_Obj, const TString &_ToFind) const {
33 TObjString *str(dynamic_cast<TObjString*>(_Obj));
34 if(!str)
35 return false;
36 return !str->String().CompareTo(_ToFind);
37 }
38 };
39
40//______________________________________________________________________________
41 template<class T>
42 Int_t find_string(const T &_Container, const TString &_ToFind)
43 {
44 // This function retuns an index in _Container of found element.
45 // Returns -1 if there was no element found.
46
47 typedef TIterCategory<T> iterator_t;
48
49 iterator_t iter(&_Container);
50 iterator_t found(
51 std::find_if(iter.Begin(), iterator_t::End(), std::bind(SFind_t(), std::placeholders::_1, _ToFind))
52 );
53 return ((!(*found)) ? -1 : std::distance(iter.Begin(), found));
54 }
55
56//______________________________________________________________________________
57// 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)...
58 struct ToLower_t {
59 char operator()(char c) const {
60 return std::tolower(c);
61 }
62 };
63
64}
65#endif
#define c(i)
Definition: RSha256.hxx:101
long long Long64_t
Definition: RtypesCore.h:71
Collectable string class.
Definition: TObjString.h:28
TString & String()
Definition: TObjString.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
Int_t find_string(const T &_Container, const TString &_ToFind)
std::string dig2bytes(Long64_t bytes)
This function creates a string representation of the number of bytes, represented as a number in B,...
double T(double x)
Definition: ChebyshevPol.h:34
void End()
bool operator()(TObject *_Obj, const TString &_ToFind) const
char operator()(char c) const