Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(GPOS_VERSION_STRING ${GPOS_VERSION_MAJOR}.${GPOS_VERSION_MINOR})
# doubt, do the safe thing and increment this number.
set(GPOS_ABI_VERSION 10)

set(CMAKE_CXX_STANDARD 11)
# Configure CCache if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
Expand Down
56 changes: 16 additions & 40 deletions libgpos/include/gpos/common/CAutoP.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#ifndef GPOS_CAutoP_H
#define GPOS_CAutoP_H

#include <type_traits>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?


#include "gpos/base.h"
#include "gpos/common/CAutoPointerBase.h"
#include "gpos/common/CRefCount.h"
#include "gpos/common/CStackObject.h"

namespace gpos
Expand All @@ -38,13 +42,14 @@ namespace gpos
//
//---------------------------------------------------------------------------
template <class T>
class CAutoP : public CStackObject
class CAutoP : public CAutoPointerBase<T>
{
private:
static_assert(!std::is_base_of<CRefCount, T>::value, "T must not be a CRefCount");

protected:
typedef CAutoPointerBase<T> _base;

// actual element to point to
T *m_pt;
protected:

// hidden copy ctor
CAutoP<T>
Expand All @@ -58,52 +63,23 @@ namespace gpos
explicit
CAutoP<T>()
:
m_pt(NULL)
_base(NULL)
{}

explicit
CAutoP<T>(T *pt)
:
m_pt(pt)
_base(pt)
{}

// dtor
virtual ~CAutoP();

// simple assignment
CAutoP<T> const & operator = (T* pt)
CAutoP const& operator = (T* pt)
{
m_pt = pt;
_base::m_pt = pt;
return *this;
}

// deref operator
T &operator * ()
{
GPOS_ASSERT(NULL != m_pt);
return *m_pt;
}

// returns only base pointer, compiler does appropriate deref'ing
T* operator -> ()
{
return m_pt;
}

// return basic pointer
T* Pt()
{
return m_pt;
}

// unhook pointer from auto object
T* PtReset()
{
T* pt = m_pt;
m_pt = NULL;
return pt;
}

// dtor
virtual ~CAutoP();
}; // class CAutoP

//---------------------------------------------------------------------------
Expand All @@ -117,7 +93,7 @@ namespace gpos
template <class T>
CAutoP<T>::~CAutoP()
{
GPOS_DELETE(m_pt);
GPOS_DELETE(_base::m_pt);
}
}

Expand Down
53 changes: 53 additions & 0 deletions libgpos/include/gpos/common/CAutoPointerBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef GPOS_CAUTOPOINTERBASE_H
#define GPOS_CAUTOPOINTERBASE_H

#include "CStackObject.h"

namespace gpos
{
template<typename T>
class CAutoPointerBase: public CStackObject
{
protected:
CAutoPointerBase<T>()
: m_pt(NULL)
{}

CAutoPointerBase<T>(T* pt)
: m_pt(pt)
{}
// actual element to point to
T *m_pt;
public:

// deref operator
T &operator * ()
{
GPOS_ASSERT(NULL != m_pt);
return *m_pt;
}

// returns only base pointer, compiler does appropriate deref'ing
T* operator -> ()
{
return m_pt;
}

// return basic pointer
T* Pt()
{
return m_pt;
}

// unhook pointer from auto object
T* PtReset()
{
T* pt = m_pt;
m_pt = NULL;
return pt;
}
};
}


#endif //GPOS_CAUTOPOINTERBASE_H
22 changes: 12 additions & 10 deletions libgpos/include/gpos/common/CAutoRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#ifndef GPOS_CAutoRef_H
#define GPOS_CAutoRef_H

#include <type_traits>

#include "gpos/base.h"
#include "gpos/common/CAutoP.h"
#include "gpos/common/CAutoPointerBase.h"
#include "gpos/common/CRefCount.h"

namespace gpos
Expand All @@ -32,10 +34,13 @@ namespace gpos
//
//---------------------------------------------------------------------------
template <class T>
class CAutoRef : public CAutoP<T>
class CAutoRef : public CAutoPointerBase<T>
{

private:
static_assert(std::is_base_of<CRefCount, T>::value, "T must be a CRefCount");

typedef CAutoPointerBase<T> _base;

// hidden copy ctor
CAutoRef<T>
Expand All @@ -49,22 +54,22 @@ namespace gpos
explicit
CAutoRef<T>()
:
CAutoP<T>()
_base()
{}

// ctor
explicit
CAutoRef<T>(T *pt)
:
CAutoP<T>(pt)
_base(pt)
{}

virtual ~CAutoRef();

// simple assignment
CAutoRef<T> const & operator = (T* pt)
{
CAutoP<T>::m_pt = pt;
_base::m_pt = pt;
return *this;
}

Expand All @@ -81,13 +86,10 @@ namespace gpos
template <class T>
CAutoRef<T>::~CAutoRef()
{
if (NULL != CAutoP<T>::m_pt)
if (NULL != _base::m_pt)
{
reinterpret_cast<CRefCount*>(CAutoP<T>::m_pt)->Release();
_base::m_pt->Release();
}

// null out pointer before ~CAutoP() gets called
CAutoP<T>::m_pt = NULL;
}
}

Expand Down
1 change: 1 addition & 0 deletions libgpos/src/common/CBitSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//---------------------------------------------------------------------------

#include "gpos/base.h"
#include "gpos/common/CAutoP.h"
#include "gpos/common/CAutoRef.h"
#include "gpos/common/CBitSet.h"
#include "gpos/common/CBitSetIter.h"
Expand Down
2 changes: 1 addition & 1 deletion make/gpo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CFLAGS_WARN = -Wall -Werror -Wextra -pedantic-errors -Wno-variadic-macros -Wconv
CFLAGS_debug = -g3 -DGPOS_DEBUG
CFLAGS_opt = -O3 -fno-omit-frame-pointer -g3

CFLAGS_TYPE = $(CFLAGS_$(BLD_TYPE))
CFLAGS_TYPE = -std=gnu++0x $(CFLAGS_$(BLD_TYPE))

ifeq ($(ARCH_BIT), GPOS_32BIT)
ARCH_FLAGS = -m32
Expand Down