xorp

bug_catcher.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2012 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 //
00017 
00018 
00019 #ifndef __XORP_BUG_CATCHER_INC__
00020 #define __XORP_BUG_CATCHER_INC__
00021 
00022 #include <assert.h>
00023 
00024 class BugCatcher {
00025 private:
00026    unsigned int magic;
00027    static unsigned int _cnt;
00028 
00029 public:
00030 #define X_BUG_CATCHER_MAGIC 0x1234543
00031    BugCatcher() { magic = X_BUG_CATCHER_MAGIC; _cnt++; }
00032    BugCatcher(const BugCatcher& rhs) { magic = rhs.magic; _cnt++; }
00033    virtual ~BugCatcher() { assert_not_deleted(); magic = 0xdeadbeef; _cnt--; }
00034 
00035    virtual void assert_not_deleted() const {
00036       assert(magic == X_BUG_CATCHER_MAGIC);
00037    }
00038 
00039    static int get_instance_count() { return _cnt; }
00040 };
00041 
00042 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations