ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00010 //------------------------------------------------------------------------- 00011 #ifndef __mlMemoryImage_H 00012 #define __mlMemoryImage_H 00013 00014 // ML-includes 00015 #ifndef __mlInitSystemML_H 00016 #include "mlInitSystemML.h" 00017 #endif 00018 #ifndef __mlRuntime_H 00019 #include "mlRuntime.h" 00020 #endif 00021 #ifndef __mlRuntimeSubClass_H 00022 #include "mlRuntimeSubClass.h" 00023 #endif 00024 #ifndef __mlSubImage_H 00025 #include "mlSubImage.h" 00026 #endif 00027 00028 #include <mlMetaProfilePtr.h> 00029 00030 00031 ML_START_NAMESPACE 00032 00034 class MemoryImageCurrentlyUsedMemoryTracker; 00035 class Module; 00036 class PagedImage; 00038 00039 //------------------------------------------------------------------------- 00050 //------------------------------------------------------------------------- 00051 class ML_UNIX_ONLY_EXPORT(MLEXPORT) MemoryImage 00052 { 00053 00054 public: 00055 00056 //------------------------------------------------------ 00058 00059 //------------------------------------------------------ 00061 inline MemoryImage() : 00062 _subImg(), 00063 _isValid(false), 00064 _userControlled(false), 00065 _calculationPending(false), 00066 _calculationPendingProcessingScope(-1), 00067 _currentlyUsedMemoryTracker(NULL) 00068 { 00069 ML_TRACE_IN( "MemoryImage::MemoryImage( )" ); 00070 } 00071 00073 MLEXPORT virtual ~MemoryImage(); 00075 00076 00077 //------------------------------------------------------ 00079 00080 //------------------------------------------------------ 00082 inline SubImage& getImage() { return _subImg; } 00083 00085 inline const SubImage& getImage() const { return _subImg; } 00086 00088 inline void setValid(bool valid) 00089 { 00090 ML_TRACE_IN( "MemoryImage::setValid( )" ); 00091 ML_TRY 00092 { 00093 Lock lock(_mutex); 00094 _isValid = valid; 00095 } 00096 ML_CATCH_RETHROW; 00097 } 00098 00100 inline bool isValid() const { Lock lock(_mutex); return _isValid; } 00101 00104 inline MLint getSizeInBytes() const 00105 { 00106 ML_TRACE_IN( "MemoryImage::getSizeInBytes( )" ); 00107 ML_TRY 00108 { 00109 return _subImg.getSizeInBytes(); 00110 } 00111 ML_CATCH_RETHROW; 00112 } 00113 00126 inline void setUserControlled(bool userControlled) 00127 { 00128 _userControlled = userControlled; 00129 } 00130 00133 inline bool isUserControlled() const 00134 { 00135 return _userControlled; 00136 } 00137 00142 inline void setCalculationPending(bool flag, int processingScope = -1) 00143 { 00144 Lock lock(_mutex); 00145 _calculationPending = flag; 00146 _calculationPendingProcessingScope = processingScope; 00147 } 00148 00151 inline bool isCalculationPending(int processingScope) const 00152 { 00153 Lock lock(_mutex); 00154 return _calculationPending && (_calculationPendingProcessingScope == processingScope); 00155 } 00156 00158 MLEXPORT std::string getAsString() const; 00159 00162 MLEXPORT void clear(); 00164 00165 //----------------------------------------------------------------------------- 00174 //----------------------------------------------------------------------------- 00175 MLEXPORT MLErrorCode update(PagedImage* image, const SubImageBox& roi, MLDataType newDataType) ML_RETURN_VALUE_SHOULD_BE_USED; 00176 00177 //----------------------------------------------------------------------------- 00183 //----------------------------------------------------------------------------- 00184 MLEXPORT void updateWithSubImage(const SubImage& image); 00185 00187 MLEXPORT MLMetaProfilePtr& getMetaProfile() const; 00188 00189 private: 00190 void updateProfilingData(); 00191 00193 mutable Mutex _mutex; 00194 00196 SubImage _subImg; 00197 00199 bool _isValid; 00200 00202 bool _userControlled; 00203 00205 bool _calculationPending; 00206 00208 int _calculationPendingProcessingScope; 00209 00211 MemoryImageCurrentlyUsedMemoryTracker* _currentlyUsedMemoryTracker; 00212 00214 mutable MLMetaProfilePtr _metaProfilePtr; 00215 00216 friend class MemoryImageCurrentlyUsedMemoryTracker; 00217 00218 #ifdef ML_DEPRECATED 00219 00221 00222 00223 public: 00224 00227 MLEXPORT ML_DEPRECATED MLErrorCode update(Module *op, MLint outIndex, const SubImageBox &roi, MLDataType newDT); 00230 inline ML_DEPRECATED SubImage& getImg() { return getImage(); } 00233 inline ML_DEPRECATED const SubImage& getConstImg() const { return getImage(); } 00236 inline ML_DEPRECATED MLint getMemoryImgSize() const { return getSizeInBytes(); } 00239 inline MLEXPORT ML_DEPRECATED void clearMemoryImg() { clear(); } 00242 inline MLEXPORT ML_DEPRECATED void updateWithSubImg(const SubImage& image) { updateWithSubImage(image); } 00245 inline ML_DEPRECATED void setManualControl(bool flag) { return setUserControlled(flag); } 00248 inline ML_DEPRECATED bool getManualControl() const { return isUserControlled(); } 00249 00251 00252 #endif // ML_DEPRECATED 00253 00254 }; 00255 00256 00257 #ifdef ML_DEPRECATED 00258 00259 00260 00261 00262 ML_DEPRECATED typedef MemoryImage MemoryImg; 00264 #endif // ML_DEPRECATED 00265 00266 00267 ML_END_NAMESPACE 00268 00269 00270 00271 //----------------------------------------------------------------------------------- 00272 // Stream output for std::ostream 00273 //----------------------------------------------------------------------------------- 00274 namespace std { 00275 00277 inline ostream& operator<<(ostream& s, const ML_NAMESPACE::MemoryImage &mi) 00278 { 00279 return s << mi.getAsString().c_str(); 00280 } 00281 00282 } 00283 00284 00285 #endif // __mlMemoryImage_H 00286 00287 00288