SmartSegment.h
1 // Copyright (c) Tech Soft 3D
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #pragma once
11 
12 #include <hc.h>
13 
14 #include "SegmentKey3DF.h"
15 
17 {
18 public:
19  SmartSegment()
20  : m_key(HC_ERROR_KEY)
21  {
22  }
23 
24  explicit SmartSegment(HC_KEY key)
25  : m_key(key)
26  {
27  HC_Open_Segment_By_Key(m_key);
28  }
29 
30  explicit SmartSegment(SegmentKey & segment)
31  : m_key(static_cast<SegmentKey3DF &>(segment).Get())
32  {
33  HC_Open_Segment_By_Key(m_key);
34  }
35 
36  explicit SmartSegment(const char *segmentName)
37  : m_key(HC_Open_Segment(segmentName))
38  {
39  }
40 
41  void Open(HC_KEY key)
42  {
43  if(key != HC_ERROR_KEY) {
44  HC_Open_Segment_By_Key(key);
45  }
46 
47  m_key = key;
48  }
49 
50  void Open(const char *segmentName)
51  {
52  m_key = HC_Open_Segment(segmentName);
53  }
54 
55  ~SmartSegment() { Release(); }
56 
57  HC_KEY Get() { return m_key; }
58 
59  void Swap(SmartSegment& other) { std::swap(m_key, other.m_key); }
60 
61  void Release()
62  {
63  if(m_key != HC_ERROR_KEY) {
64  HC_Close_Segment();
65  m_key = HC_ERROR_KEY;
66  }
67  }
68 
69 private:
70  SmartSegment(const SmartSegment&);
71  SmartSegment& operator=(const SmartSegment&);
72  SmartSegment(SegmentKeyPtr &);
73 
74 private:
75  HC_KEY m_key;
76 };
#define HC_KEY
Definition: SmartSegment.h:16