FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
memory_utils.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (1 Mar. 2011)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include <cstddef>
19 
20 namespace cpp {
21 
25 template <typename T>
26 std::size_t scalarAddress(const T* pointer)
27 {
28  return reinterpret_cast<std::size_t>(pointer);
29 }
30 
34 template<typename T>
35 void checkedReset(T*& pointer)
36 {
37  if (pointer != NULL) {
38  delete pointer;
39  pointer = NULL;
40  }
41 }
42 
46 template<typename T>
47 void checkedAssign(T* pointer, T value)
48 {
49  if (pointer != NULL)
50  *pointer = value;
51 }
52 
56 template<typename CALL_VALUE_TYPE, typename VALUE_TYPE, typename CLASS>
57 void checkedAssign(VALUE_TYPE CLASS::*attrMember, CLASS* object, CALL_VALUE_TYPE value)
58 {
59  if (object != NULL && attrMember != NULL)
60  object->*attrMember = value;
61 }
62 
69 template<typename T>
71 {
72  return new T;
73 }
74 
75 template<typename T, typename ARG>
76 T* newObject(ARG arg)
77 {
78  return new T(arg);
79 }
80 
81 } // namespace cpp
void checkedReset(T *&pointer)
Definition: memory_utils.h:35
Definition: basic_shared_pointer.h:20
std::size_t scalarAddress(const T *pointer)
Definition: memory_utils.h:26
void checkedAssign(T *pointer, T value)
Definition: memory_utils.h:47
T * newObject()
Definition: memory_utils.h:70