00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc. 00002 // 00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., 00004 // and considered a trade secret as defined under civil and criminal statutes. 00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of 00006 // unauthorized use or misappropriation of its trade secrets. Use of this information 00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under 00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use. 00009 00010 #pragma once 00011 00012 #include <hc.h> 00013 00014 #include "SegmentKey3DF.h" 00015 00016 class SmartSegment 00017 { 00018 public: 00019 SmartSegment() 00020 : m_key(HC_ERROR_KEY) 00021 { 00022 } 00023 00024 explicit SmartSegment(HC_KEY key) 00025 : m_key(key) 00026 { 00027 HC_Open_Segment_By_Key(m_key); 00028 } 00029 00030 explicit SmartSegment(SegmentKey & segment) 00031 : m_key(static_cast<SegmentKey3DF &>(segment).Get()) 00032 { 00033 HC_Open_Segment_By_Key(m_key); 00034 } 00035 00036 explicit SmartSegment(const char *segmentName) 00037 : m_key(HC_Open_Segment(segmentName)) 00038 { 00039 } 00040 00041 void Open(HC_KEY key) 00042 { 00043 if(key != HC_ERROR_KEY) { 00044 HC_Open_Segment_By_Key(key); 00045 } 00046 00047 m_key = key; 00048 } 00049 00050 void Open(const char *segmentName) 00051 { 00052 m_key = HC_Open_Segment(segmentName); 00053 } 00054 00055 ~SmartSegment() { Release(); } 00056 00057 HC_KEY Get() { return m_key; } 00058 00059 void Swap(SmartSegment& other) { std::swap(m_key, other.m_key); } 00060 00061 void Release() 00062 { 00063 if(m_key != HC_ERROR_KEY) { 00064 HC_Close_Segment(); 00065 m_key = HC_ERROR_KEY; 00066 } 00067 } 00068 00069 private: 00070 SmartSegment(const SmartSegment&); 00071 SmartSegment& operator=(const SmartSegment&); 00072 SmartSegment(SegmentKeyPtr &); 00073 00074 private: 00075 HC_KEY m_key; 00076 };