MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
cleanup.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbutil/cleanup.cc,v 1.9 2017/01/12 14:44:04 masarati Exp $*/
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 #include "myassert.h"
35 #include "cleanup.h"
36 
37 #include <stack>
38 
39 struct cleanup {
41  void *data;
42 
43 public:
45  ~cleanup(void);
46 };
47 
49 : handler(handler), data(0)
50 {
51  NO_OP;
52 }
53 
55 {
56  NO_OP;
57 }
58 
59 static std::stack<cleanup *> c;
60 
61 extern "C" int
62 mbdyn_cleanup_register(mbdyn_cleanup_f handler, void ***datapp)
63 {
64 
65  pedantic_cout("mbdyn_cleanup_register: " << (void *)handler << ":" << (void *)datapp << std::endl);
66 
67  cleanup *p = new cleanup(handler);
68  if (datapp != 0) {
69  *datapp = &p->data;
70  }
71  c.push(p);
72 
73  return 0;
74 }
75 
76 extern "C" int
78 {
79  while (!c.empty()) {
80  cleanup *p = c.top();
81 
82  pedantic_cout("mbdyn_cleanup: " << (void *)p->handler << ":" << (void *)p->data << std::endl);
83 
84  p->handler(p->data);
85  c.pop();
86  delete p;
87  }
88 
89  return 0;
90 }
91 
92 extern "C" void
94 {
95  while (!c.empty()) {
96  cleanup *p = c.top();
97  c.pop();
98  delete p;
99  }
100 }
101 
int mbdyn_cleanup_register(mbdyn_cleanup_f handler, void ***datapp)
Definition: cleanup.cc:62
#define NO_OP
Definition: myassert.h:74
int mbdyn_cleanup(void)
Definition: cleanup.cc:77
cleanup(mbdyn_cleanup_f handler)
Definition: cleanup.cc:48
mbdyn_cleanup_f handler
Definition: cleanup.cc:40
~cleanup(void)
Definition: cleanup.cc:54
static std::stack< cleanup * > c
Definition: cleanup.cc:59
int(* mbdyn_cleanup_f)(void *)
Definition: cleanup.h:39
void * data
Definition: cleanup.cc:41
void mbdyn_cleanup_destroy(void)
Definition: cleanup.cc:93