View | Details | Raw Unified | Return to bug 147
Collapse All | Expand All

(-)1ef7ee05ec04 (+36 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 Georgia Tech Research Corporation
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author:  George Riley <riley@ece.gatech.edu>
19
 * Adapted from original code in object.h by:
20
 * Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
21
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
22
 */
23
24
#include "ref-count-base.h"
25
26
namespace ns3 {
27
28
RefCountBase::RefCountBase() : m_count (0) 
29
{
30
}
31
32
RefCountBase::~RefCountBase () 
33
{
34
}
35
36
} // namespace ns3
(-)1ef7ee05ec04 (+77 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 Georgia Tech Research Corporation
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author:  George Riley <riley@ece.gatech.edu>
19
 * Adapted from original code in object.h by:
20
 * Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
21
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
22
 */
23
#ifndef __REF_COUNT_BASE_H__
24
#define __REF_COUNT_BASE_H__
25
26
#include <stdint.h>
27
/**
28
 * \brief a base class that provides implementations of reference counting
29
 *    operations.
30
 *  
31
 * A base class that provides implementations of reference counting 
32
 * operations, for classes that wish to use the templatized smart 
33
 * pointer for memory management but that do not wish to derive from
34
 * class ns3::Object.
35
 *
36
 */
37
class RefCountBase 
38
{ 
39
public:
40
 RefCountBase();
41
 virtual ~RefCountBase ();
42
  /**
43
   * Increment the reference count. This method should not be called
44
   * by user code. RefCountBase instances are expected to be used in
45
   * conjunction with the Ptr template which would make calling Ref
46
   * unecessary and dangerous.
47
   */
48
  inline void Ref () const;
49
  /**
50
   * Decrement the reference count. This method should not be called
51
   * by user code. RefCountBase instances are expected to be used in 
52
   * conjunction with the Ptr template which would make calling Ref
53
   * unecessary and dangerous.
54
   */
55
  inline void Unref () const;
56
private:
57
  // Note we make this mutable so that the const methods can still
58
  // change it.
59
  mutable uint32_t m_count;  // Reference count
60
};
61
62
// Implementation of the in-line methods
63
void
64
RefCountBase::Ref () const
65
{
66
  m_count++;
67
}
68
69
void
70
RefCountBase::Unref () const
71
{
72
  if (--m_count == 0)
73
    { // All references removed, ok to delete
74
      delete this;
75
    }
76
}
77
#endif
(-)a/src/core/wscript (+2 lines)
 Lines 32-37   def build(bld): Link Here 
32
        'log.cc',
32
        'log.cc',
33
        'breakpoint.cc',
33
        'breakpoint.cc',
34
        'object-base.cc',
34
        'object-base.cc',
35
        'ref-count-base.cc',
35
        'ptr.cc',
36
        'ptr.cc',
36
        'object.cc',
37
        'object.cc',
37
        'test.cc',
38
        'test.cc',
 Lines 73-78   def build(bld): Link Here 
73
        'empty.h',
74
        'empty.h',
74
        'callback.h',
75
        'callback.h',
75
        'object-base.h',
76
        'object-base.h',
77
        'ref-count-base.h',
76
        'ptr.h',
78
        'ptr.h',
77
        'object.h',
79
        'object.h',
78
        'log.h',
80
        'log.h',

Return to bug 147