Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Added uniqe_ptr functionality for ert managed objects. #1001

Merged
merged 1 commit into from Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions devel/CMakeLists.txt
Expand Up @@ -152,7 +152,10 @@ include_directories( ${PROJECT_SOURCE_DIR}/libecl/include )
add_subdirectory( libecl )

if (ERT_BUILD_CXX)
include_directories( ${PROJECT_SOURCE_DIR}/libert_utilxx/include )
include_directories( ${PROJECT_SOURCE_DIR}/libeclxx/include )

add_subdirectory( libert_utilxx )
add_subdirectory( libeclxx )
endif()

Expand Down
3 changes: 3 additions & 0 deletions devel/libert_utilxx/CMakeLists.txt
@@ -0,0 +1,3 @@
if (BUILD_TESTS)
add_subdirectory( tests )
endif()
23 changes: 23 additions & 0 deletions devel/libert_utilxx/include/ert/util/ert_unique_ptr.hpp
@@ -0,0 +1,23 @@
#ifndef ERT_UNIQUE_PTR
#define ERT_UNIQUE_PTR

#include <memory>

namespace ERT {

template <typename T , void (*F)(T*)>
struct deleter
{
void operator() (T * arg) const {
F( arg );
}
};

template <typename T , void (*F)(T*)>
using ert_unique_ptr = std::unique_ptr<T, deleter<T,F> >;

}

#endif


3 changes: 3 additions & 0 deletions devel/libert_utilxx/tests/CMakeLists.txt
@@ -0,0 +1,3 @@
add_executable(ert_util_unique_ptr ert_util_unique_ptr.cpp )
target_link_libraries(ert_util_unique_ptr test_util util)
add_test(ert_util_unique_ptr ${EXECUTABLE_OUTPUT_PATH}/ert_util_unique_ptr)
31 changes: 31 additions & 0 deletions devel/libert_utilxx/tests/ert_util_unique_ptr.cpp
@@ -0,0 +1,31 @@
/*
Copyright (C) 2016 Statoil ASA, Norway.

This is part of ERT - Ensemble based Reservoir Tool.

ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or1
FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/

#include <ert/util/ert_unique_ptr.hpp>
#include <ert/util/stringlist.h>


void test_stringlist() {
ERT::ert_unique_ptr<stringlist_type , stringlist_free> stringlist(stringlist_alloc_new( ));
stringlist_append_copy( stringlist.get() , "Hello");
}


int main(int argc , char **argv) {
test_stringlist();
}