PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
counted_ptr< X > Class Template Reference

#include <rc_ptrs.h>

Public Types

typedef X element_type
 
typedef X * pointer_type
 
typedef size_t size_type
 

Public Member Functions

 counted_ptr (X *p=0)
 
 counted_ptr (const counted_ptr< X > &r)
 
 ~counted_ptr ()
 
counted_ptroperator= (const counted_ptr< X > &r)
 
X & operator* () const
 
X * get () const
 
X * operator-> () const
 
bool unique () const
 
void PrintCounts ()
 

Protected Member Functions

void acquire ()
 
void release ()
 

Protected Attributes

X * ptr
 
size_typecount
 

Detailed Description

template<class X>
class counted_ptr< X >

Definition at line 65 of file rc_ptrs.h.

Member Typedef Documentation

◆ element_type

template<class X >
typedef X counted_ptr< X >::element_type

Definition at line 71 of file rc_ptrs.h.

◆ pointer_type

template<class X >
typedef X* counted_ptr< X >::pointer_type

Definition at line 72 of file rc_ptrs.h.

◆ size_type

template<class X >
typedef size_t counted_ptr< X >::size_type

Definition at line 73 of file rc_ptrs.h.

Constructor & Destructor Documentation

◆ counted_ptr() [1/2]

template<class X >
counted_ptr< X >::counted_ptr ( X *  p = 0)
inlineexplicit

Definition at line 76 of file rc_ptrs.h.

76 : ptr(p)
77 {
78 // Debug: std::cout <<"[RC_PTR] INITIATING counted_ptr for " << ptr << std::endl;
79 count=new size_type(1);
80 }
size_t size_type
Definition rc_ptrs.h:73
size_type * count
Definition rc_ptrs.h:125

References counted_ptr< X >::count.

◆ counted_ptr() [2/2]

template<class X >
counted_ptr< X >::counted_ptr ( const counted_ptr< X > &  r)
inline

Definition at line 83 of file rc_ptrs.h.

84 {
85 // Debug: std::cout <<"[RC_PTR] COPY CONSTRUCTOR for ["<< r.ptr << "]"<<std::endl;
86 ptr=r.ptr;
87 count=r.count;
88 acquire();
89 }
void acquire()
Definition rc_ptrs.h:129

References counted_ptr< X >::acquire(), counted_ptr< X >::count, and counted_ptr< X >::ptr.

◆ ~counted_ptr()

template<class X >
counted_ptr< X >::~counted_ptr ( )
inline

Definition at line 92 of file rc_ptrs.h.

92 {
93 release();
94 }
void release()
Definition rc_ptrs.h:137

References counted_ptr< X >::release().

Member Function Documentation

◆ acquire()

template<class X >
void counted_ptr< X >::acquire ( )
inlineprotected

Definition at line 129 of file rc_ptrs.h.

130 {
131 // Debug: std::cout << "[RC_PTR] >>>>ACQUIRING " << ptr << "\n";
132 (*count) += 1;
133 // Debug: PrintCounts();
134 }

Referenced by counted_ptr< X >::counted_ptr(), and counted_ptr< X >::operator=().

◆ get()

template<class X >
X * counted_ptr< X >::get ( ) const
inline

Definition at line 110 of file rc_ptrs.h.

110{ return ptr; }

References counted_ptr< X >::ptr.

Referenced by PEBLList::Append(), Evaluator::CallFunction(), PEBLList::CrossFactorWithoutDuplicates(), PEBLList::DesignFullCounterbalance(), PlatformTextBox::Draw(), PlatformWindow::Draw(), PEBLObjects::Draw(), PEBLObjects::DrawFor(), PEBLStream::EndOfFile(), PEBLStream::EndOfLine(), Variant::Equal(), Evaluator::Evaluate(), Evaluator::Evaluate1(), PEBLList::Fifth(), PEBLStream::FileClose(), PEBLStream::FilePrint(), PEBLStream::FilePrint_(), PEBLStream::FileReadCharacter(), PEBLStream::FileReadLine(), PEBLStream::FileReadWord(), PEBLList::First(), PEBLList::Fourth(), PEBLObjects::GetAudioStats(), PFont::GetBackgroundColorPtr(), PDrawObject::GetColor(), PEBLObjects::GetCursorPosition(), PEBLObjects::GetEyeObject(), PlatformTextBox::GetFont(), PFont::GetFontColorPtr(), PEBLEnvironment::GetInput0(), PEBLEnvironment::GetJoystickAxisState(), PEBLEnvironment::GetJoystickBallState(), PEBLEnvironment::GetJoystickButtonState(), PEBLEnvironment::GetJoystickHatState(), PEBLObjects::GetLineBreaks(), PComplexData::GetList(), PEBLEnvironment::GetNumJoystickAxes(), PEBLEnvironment::GetNumJoystickBalls(), PEBLEnvironment::GetNumJoystickButtons(), PEBLEnvironment::GetNumJoystickHats(), PDrawObject::GetOutlineColor(), PEBLObjects::GetParent(), PEBLObjects::GetPixelColor(), PEBLObjects::GetPropertyList(), PEBLObjects::GetSize(), PEBLObjects::GetText(), PEBLEnvironment::GetTextBoxCursorFromClick(), PComplexData::GetType(), PEBLObjects::GetVocalResponseTime(), PEBLObjects::Hide(), PEBLList::IsMember(), PEBLList::Last(), PEBLList::Length(), PEBLList::ListToString(), PEBLObjects::LoadMovie(), PEBLObjects::MakeFont(), PEBLObjects::MakeWindow(), PEBLList::Merge(), PEBLList::ModList(), PEBLObjects::Move(), PEBLList::Nth(), PEBLObjects::PausePlayback(), PEBLObjects::PlayBackground(), PEBLObjects::PlayForeground(), PEBLEnvironment::PlayMovie(), PEBLObjects::PrintProperties(), PEBLList::PushOnEnd(), PEBLObjects::RecordToBuffer(), PEBLEnvironment::RegisterEvent(), PEBLObjects::RemoveObject(), PEBLList::RepeatList(), PEBLObjects::ResizeWindow(), PEBLObjects::RotoZoom(), PEBLObjects::SaveAudioToWaveFile(), PEBLList::Second(), PCanvas::SetColor(), PEBLObjects::SetCursorPosition(), PEBLObjects::SetEditable(), PEBLObjects::SetEyeTrackerHandler(), PEBLObjects::SetFont(), PEBLObjects::SetPanning(), PEBLObjects::SetPlayRepeats(), PEBLObjects::SetPoint(), PFont::SetProperty(), PEBLObjects::SetText(), PEBLObjects::Show(), PEBLList::Shuffle(), PEBLList::Sort(), PEBLList::SortBy(), PEBLObjects::StartPlayback(), PEBLObjects::Stop(), PEBLObjects::StopAudioMonitor(), PEBLList::SubList(), PEBLList::Third(), PEBLList::Transpose(), and PEBLStream::WritePNG().

◆ operator*()

template<class X >
X & counted_ptr< X >::operator* ( ) const
inline

Definition at line 109 of file rc_ptrs.h.

109{ return *ptr; }

References counted_ptr< X >::ptr.

◆ operator->()

template<class X >
X * counted_ptr< X >::operator-> ( ) const
inline

Definition at line 111 of file rc_ptrs.h.

111{ return ptr; }

References counted_ptr< X >::ptr.

◆ operator=()

template<class X >
counted_ptr & counted_ptr< X >::operator= ( const counted_ptr< X > &  r)
inline

Definition at line 97 of file rc_ptrs.h.

98 {
99 if (this != &r)
100 {
101 release();
102 ptr = r.ptr;
103 count = r.count;
104 acquire();
105 }
106 return *this;
107 }

References counted_ptr< X >::acquire(), counted_ptr< X >::count, counted_ptr< X >::ptr, and counted_ptr< X >::release().

◆ PrintCounts()

template<class X >
void counted_ptr< X >::PrintCounts ( )
inline

Definition at line 118 of file rc_ptrs.h.

119 {
120 // Debug: std::cout << "Object "<< ptr<<" has "<< *count << " copies" <<std::endl;
121 }

◆ release()

template<class X >
void counted_ptr< X >::release ( )
inlineprotected

Definition at line 137 of file rc_ptrs.h.

138 {
139 if (count)
140 {
141 // Debug: std::cout << "[RC_PTR] <<<<<RELEASING\n";
142 // Debug: std::cout << "[RC_PTR] Object: " << ptr <<std::endl;
143 (*count)--;
144 // Debug: PrintCounts();
145
146 if((*count)==0)
147 {
148 // Debug: std::cout << "[RC_PTR] *** COUNT IS ZERO; Deleting: "<< ptr<<std::endl;
149 delete ptr;
150 delete count;
151 ptr = NULL;
152 count = NULL;
153 }
154 }
155 }
#define NULL
Definition BinReloc.cpp:317

References counted_ptr< X >::count, NULL, and counted_ptr< X >::ptr.

Referenced by counted_ptr< X >::operator=(), and counted_ptr< X >::~counted_ptr().

◆ unique()

template<class X >
bool counted_ptr< X >::unique ( ) const
inline

Definition at line 113 of file rc_ptrs.h.

114 {
115 return *count==1;
116 }

References counted_ptr< X >::count.

Member Data Documentation

◆ count

◆ ptr


The documentation for this class was generated from the following file: