RefCountedObject.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _REFCOUNTEDOBJECT_H_
00018 #define _REFCOUNTEDOBJECT_H_
00019 
00020 #include "../debug/Formatter.h"
00021 #include "../debug/Log.h"
00022 #include "../thread/Atomic.h"
00023 
00024 namespace oasys {
00025 
00049 class RefCountedObject : public Formatter {
00050 public:
00055     RefCountedObject(const char* logpath);
00056 
00060     virtual ~RefCountedObject();
00061 
00069     void add_ref(const char* what1, const char* what2 = "") const;
00070 
00078     void del_ref(const char* what1, const char* what2 = "") const;
00079 
00083     virtual void no_more_refs() const;
00084 
00088     int format(char* buf, size_t sz) const;
00089 
00093     u_int32_t refcount() const { return refcount_.value; }
00094     
00095 protected:
00097     mutable atomic_t refcount_;
00098     
00100     Logger logger_;
00101 };
00102 
00103 } // namespace oasys
00104 
00105 #endif /* _REFCOUNTEDOBJECT_H_ */

Generated on Sat Sep 8 08:36:17 2007 for DTN Reference Implementation by  doxygen 1.5.3