• Stars
    star
    178
  • Rank 214,989 (Top 5 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal shared/unique_ptr implementation to handle cases where boost/std::shared/unique_ptr are not available.

shared_ptr

shared_ptr build status

shared_ptr is a minimal implementation of smart pointer, a subset of the C++11 std::shared_ptr or boost::shared_ptr.

Shared Pointer UML

It comes with a fake implementation of a unique_ptr for C++98.

The goals of this minimal shared_ptr are:

  • to replace the C++11 std::shared_ptr and boost::shared_ptr where they are not available

  • to be a header only implementation

  • to keep dependencies to a minimum (STL)

  • to be portable

  • to be light (minimizing code size, presently 92 bytes per template usage)

  • to be fast and monothreaded (not thread-safe)

  • to be well documented with Doxygen tags

  • to have a perfect unit test coverage

  • to use a permissive MIT license, similar to BSD or Boost, for proprietary/commercial usage

  • to also provide a fake unique_ptr to be used with older compiler

Limitations

  • does not come with a weak_ptr implementation

  • does not manage array type (does not call delete[] for array allocated with new[])

  • does not manage the underlying raw pointer type separately from the template shared_ptr type : does not call delete on the right type, thus needing virtual destructor (as with raw pointer)

  • does not distinguish between the stored pointer and the owned pointer : cannot store a pointer to object member while managing a pointer to the object itself

  • not thread-safe

  • the fake unique_ptr does not at all conform to the standard, and so is only a placeholder for use with older compilers

### Supported platforms:

Developments and tests are done under the following OSs :

  • Debian 7 (testing)
  • Ubuntu 12.10
  • Windows XP/7/8 And following IDEs/Compilers
  • GCC 4.7.x with a provided Makefile
  • Eclipse CDT under Linux, using the provided Makefile
  • Visual Studio Express 2008/2010/2012 for testing compatibility purpose

Dependencies:

  • a STL implementation (even an old one, like those provided with VC6/eVC4 should work)

Installation

To use this shared_ptr implementation, you only need to include the shared_ptr.hpp file from the source code of your projects.

### Continuous Integration

This project is continuously tested under Ubuntu Linux with the gcc and clang compilers using the Travis CI community service with the above CMake building and testing procedure.

Detailed results can be seen online: https://travis-ci.org/SRombauts/shared_ptr

License

Copyright (c) 2013-2014 Sébastien Rombauts ([email protected])

Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT)

Getting started

About std::shared_ptr:

About boost::shared_ptr:

About std::unique_ptr:

First sample demonstrates how to create a shared_ptr to a class Xxx:

The Xxx class:

class Xxx
{
public:
    Xxx(size_t len = 0);
    ~Xxx(void);
    ...
    void doSomething(void);
    ...
};

shared_ptr usage:

void func(void)
{
    // Create an empty (ie. NULL) p1 shared_ptr
    shared_ptr<Xxx> xPtr;

    if (xPtr) // empty pointer
    {
        // impossible
    }
    else
    {
        // Create a new Xxx object, and give its ownership to the yPtr shared_ptr
        shared_ptr<Xxx> yPtr(new Xxx(1024));

        if (yPtr) // valid pointer
        {
            // Access members functions/variables like with a raw pointer
            yPtr->doSomething();
        }
        else
        {
            // impossible
        }

        // Share ownership by making a copy of the shared_ptr (the reference counter reaches 2)
        xPtr = yPtr;

    } // yPtr is destroyed, but xPtr retains the ownership of the object

    ...

} // xPtr is destroyed, the reference counter drops to 0 thus the object is destroyed and the memory freed

How to contribute

GitHub website

The most efficient way to help and contribute to this wrapper project is to use the tools provided by GitHub:

Contact

You can also email me directly, I will answer any questions and requests.

Coding Style Guidelines

The source code use the CamelCase naming style variant where :

  • type names (class, struct, typedef, enums...) begins with a capital letter
  • files (.cpp/.h) are named like the class they contains
  • function and variable names begins with a lower case letter
  • member variables begins with a 'm', function arguments begins with a 'a', boolean with a 'b', pointers with a 'p'
  • each file, class, method and member variable is documented using Doxygen tags See also http://www.appinf.com/download/CppCodingStyleGuide.pdf for good guidelines

More Repositories

1

SQLiteCpp

SQLiteC++ (SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper.
C
2,150
star
2

UEGitPlugin

Unreal Engine 5 Git LFS 2 Source Control Plugin (beta)
C++
820
star
3

SimplexNoise

A Perlin's Simplex Noise C++ Implementation (1D, 2D, 3D)
C++
320
star
4

UE4ProceduralMesh

UE4.7 Procedural Mesh Generation plugin
C++
169
star
5

UEPlasticPlugin

Plastic SCM Plugin for Unreal Engine
C++
148
star
6

LoggerCpp

LoggerC++ (LoggerCpp) is a simple, elegant and efficient C++ logger library.
C++
62
star
7

ecs

A small and easy C++ Entity-Component-System (ECS) library
Python
51
star
8

UE4QuickStart

Unreal Engine 4.10 C++ Programming Quick Start Tutorials
C++
34
star
9

HtmlBuilder

A simple C++ HTML Generator
C++
30
star
10

SQLiteCpp_Example

C++ Example project using SQLiteCpp as a Git submodule / CMake subdirectory
C++
25
star
11

UE4ArchVisDemo

Architecture Visualization Demo with Unreal Engine 4
14
star
12

UE4StealthGame

Unreal Engine 4 FPSGame C++ Template modified to become a Multiplayer Stealth Game
C++
12
star
13

cpp-skeleton

A simple skeleton for C++ development with CMake and Google Test.
C++
10
star
14

UE4CoopGame

Unreal Engine 4 C++ TPS Multiplayer Coop Game
C++
8
star
15

UE4_Paper2D_2048

Unreal Engine 4 Paper2D clone of 2048 (http://gabrielecirulli.github.io/2048/)
7
star
16

UE4ShooterGame

UE4.19 C++ Shooter Game
C++
6
star
17

SimplexNoiseCImg

A simple 2D Map Generator using my SimplexNoise and CImg
C
6
star
18

cmake-basics

Using the CMake tutorial to test Travis-CI
C++
6
star
19

CrashHandler

A basic Linux crash signal handler in C
C
6
star
20

UE4Tanks

Unreal Engine Tanks Tutorial from Epic Games currently on Twitch
C++
6
star
21

glload

The OpenGL Loading Library (GL Load) is the Unofficial OpenGL SDK library for initializing OpenGL's functions.
C
5
star
22

opengl-experiments

Some basic experiments with the Unofficial OpenGL SDK
C++
5
star
23

sdlman

Test SDL2 with CMake Travis CI AppVeyor...
C
4
star
24

ZMQCpp

ZMQC++ (ZMQCpp) is a smart and easy to use C++ wrapper of the ZeroMQ messaging library.
C++
4
star
25

cpp-algorithms

Experimenting with well known algorithms and data structures. Hash and random functions
C++
3
star
26

UE4BasicCode

Test of a basic C++ code project for Unreal Engine 4
C++
3
star
27

BoostHttpServer

Improvements on top of the Boost Asio HTTP server example
C++
3
star
28

UE4CustomSettings

C++
3
star
29

srombauts.github.io

SRombauts GitHub Pages
CSS
2
star
30

cpplint

cpplint checks for compliance with Google C++ Style Guide (with modifications)
Python
2
star
31

gltext

Simple C++ library to render text with Freetype2 and Harfbuzz under OpenGL 3
C++
2
star
32

UE4Menus

Unreal Engine 4 Main and Pause Menus using a dedicated level
2
star
33

glfw_fullscreen

Minimal application to demonstrate fullscreen glwf mode
C++
1
star
34

codingame-great-escape

My attempt at the CodinGame multiplayer contest "The Great Escape"
C++
1
star
35

UE4VrDevKit

UE4.21 demo with Oculus Go mobile Headset
1
star
36

freetype-experiments

Experiments with freetype2 and gltext in OpenGL
C++
1
star
37

cpp-basics

Small example to show some basic features of C++
C++
1
star
38

unique_ptr

Famous C++03 unique_ptr implementation rescued from the lost http://home.roadrunner.com/~hinnant/unique_ptr03.html
C++
1
star