ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSmapsFileParser.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkSmapsFileParser_h
00019 #define __itkSmapsFileParser_h
00020 
00021 #include "itkMacro.h"
00022 #include "itkIntTypes.h"
00023 
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 #include <istream>
00028 #include <iostream>
00029 
00030 namespace itk
00031 {
00038 class ITKCommon_EXPORT MapRecord
00039 {
00040 public:
00041   typedef SizeValueType  MemoryLoadType;
00042   virtual ~MapRecord();
00045   void Reset(void);
00046 
00049   std::string m_RecordName;
00050 
00055   std::map< std::string, MemoryLoadType > m_Tokens;
00056 };
00057 
00064 class ITKCommon_EXPORT SmapsRecord:public MapRecord
00065 {
00082   friend ITKCommon_EXPORT std::istream &  operator>>(std::istream & in, SmapsRecord & record);
00083 };
00084 
00091 class ITKCommon_EXPORT VMMapSummaryRecord:public MapRecord
00092 {
00098   friend ITKCommon_EXPORT std::istream &  operator>>(std::istream & in, VMMapSummaryRecord & record);
00099 };
00100 
00107 class ITKCommon_EXPORT VMMapRecord:public MapRecord
00108 {
00114   friend ITKCommon_EXPORT std::istream &  operator>>(std::istream & in, VMMapRecord & record);
00115 };
00116 
00125 class ITKCommon_EXPORT MapData
00126 {
00127 public:
00129   typedef SizeValueType  MemoryLoadType;
00130   //todo delete records
00131   virtual ~MapData();
00132 
00134   virtual MemoryLoadType GetHeapUsage() = 0;
00135 
00137   virtual MemoryLoadType GetStackUsage() = 0;
00138 
00140   virtual MemoryLoadType GetTotalMemoryUsage();
00141 
00143   virtual MemoryLoadType GetMemoryUsage(const char *filter, const char *token);
00144 
00146   bool Empty();
00147 
00148 protected:
00150   void Reset(void);
00151 
00152 protected:
00153   typedef std::vector< MapRecord * > MapRecordVectorType;
00154 
00156   MapRecordVectorType m_Records;
00157 };
00158 
00164 class ITKCommon_EXPORT SmapsData_2_6:public MapData
00165 {
00166 public:
00167   typedef MapData::MemoryLoadType MemoryLoadType;
00168 
00169   virtual ~SmapsData_2_6();
00170 
00172   virtual MemoryLoadType GetHeapUsage();
00173 
00175   virtual MemoryLoadType GetStackUsage();
00176 
00178   friend ITKCommon_EXPORT std::istream &  operator>>(std::istream & smapsStream,
00179                                                      SmapsData_2_6 & data);
00180 
00181 protected:
00182   bool m_HeapRecordFound;
00183 };
00184 
00193 class ITKCommon_EXPORT VMMapData_10_2:public MapData
00194 {
00195 public:
00196   typedef MapData::MemoryLoadType MemoryLoadType;
00197   VMMapData_10_2();
00198   virtual ~VMMapData_10_2();
00199 
00201   virtual MemoryLoadType GetHeapUsage();
00202 
00204   virtual MemoryLoadType GetStackUsage();
00205 
00207   friend ITKCommon_EXPORT std::istream & operator>>(std::istream & stream,
00208                                                     VMMapData_10_2 & data);
00209 
00210 protected:
00211   bool m_UsingSummary;
00212 };
00213 
00221 template< class TMapData >
00222 class ITK_EXPORT MapFileParser
00223 {
00224 public:
00225   typedef typename TMapData::MemoryLoadType MemoryLoadType;
00226 
00227   virtual ~MapFileParser();
00232   virtual void ReadFile(const std::string & mapFileLocation = "") = 0;
00233 
00237   bool Update(void);
00238 
00242   MemoryLoadType GetHeapUsage();
00243 
00247   MemoryLoadType GetStackUsage();
00248 
00252   MemoryLoadType GetTotalMemoryUsage();
00253 
00257   MemoryLoadType GetMemoryUsage(const char *filter, const char *token = "Size");
00258 
00259 protected:
00260   std::string m_MapFilePath;    //< location of the last loaded Map file
00261   TMapData    m_MapData;        //< data of the loaded smap file
00262 };
00263 
00270 template< class TSmapsDataType >
00271 class ITK_EXPORT SmapsFileParser:public MapFileParser< TSmapsDataType >
00272 {
00273 public:
00274   virtual ~SmapsFileParser();
00280   virtual void ReadFile(const std::string & mapFileLocation = "");
00281 };
00282 
00288 template< class TVMMapDataType >
00289 class ITK_EXPORT VMMapFileParser:public MapFileParser< TVMMapDataType >
00290 {
00291 public:
00292   virtual ~VMMapFileParser();
00296   virtual void ReadFile(const std::string & mapFileLocation = "");
00297 };
00298 }  // end namespace itk
00299 
00300 #ifndef ITK_MANUAL_INSTANTIATION
00301 #include "itkSmapsFileParser.hxx"
00302 #endif
00303 
00304 #endif // __itkSmapsFileParser_h
00305