My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
exceptionstack.cpp
Go to the documentation of this file.
1
/*
2
* exceptionstack.cpp - exception stack class implementation
3
*
4
* Copyright (C) 2004 Stefan Jahn <stefan@lkcc.org>
5
*
6
* This is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
9
* any later version.
10
*
11
* This software is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this package; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19
* Boston, MA 02110-1301, USA.
20
*
21
* $Id: exceptionstack.cpp 1825 2011-03-11 20:42:14Z ela $
22
*
23
*/
24
25
#if HAVE_CONFIG_H
26
# include <config.h>
27
#endif
28
29
#include <stdio.h>
30
#include <stdlib.h>
31
#include <string.h>
32
33
#include "
logging.h
"
34
#include "
exception.h
"
35
#include "
exceptionstack.h
"
36
37
using namespace
qucs;
38
39
// Global exception stack.
40
exceptionstack
qucs::estack
;
41
42
// Constructor creates an instance of the exception stack class.
43
exceptionstack::exceptionstack
() {
44
root = NULL;
45
}
46
47
/* This copy constructor creates a instance of the exception stack
48
class based on the given exception stack. */
49
exceptionstack::exceptionstack
(
const
exceptionstack
&
e
) {
50
exception
* last, * prev = NULL;
51
for
(
exception
* next = e.root; next != NULL; next = next->getNext ()) {
52
last =
new
exception
(*next);
53
if
(prev != NULL)
54
prev->
setNext
(last);
55
else
56
root = last;
57
prev = last;
58
}
59
}
60
61
// Destructor deletes an instance of the exception stack class.
62
exceptionstack::~exceptionstack
() {
63
exception
* next;
64
while
(root) {
65
next = root->
getNext
();
66
delete
root;
67
root = next;
68
}
69
}
70
71
// The function pushes a new exception onto the exception stack.
72
void
exceptionstack::push
(
exception
*
e
) {
73
e->
setNext
(root);
74
root =
e
;
75
}
76
77
/* This function removes the top exception from the exception stack
78
and returns the new top exception. */
79
exception
*
exceptionstack::pop
(
void
) {
80
if
(root != NULL) {
81
exception
* next = root->
getNext
();
82
delete
root;
83
root = next;
84
}
85
return
root;
86
}
87
88
// The function returns the top exception.
89
exception
*
exceptionstack::top
(
void
) {
90
return
root;
91
}
92
93
/* This function prints the complete exception stack and removes each
94
exception from the stack. */
95
void
exceptionstack::print
(
const
char
* prefix) {
96
exception
* next;
97
if
(root)
98
logprint
(
LOG_ERROR
,
"%s%sexception stack\n"
,
99
prefix ? prefix :
""
, prefix ?
" "
:
""
);
100
while
((next =
top
()) != NULL) {
101
logprint
(
LOG_ERROR
,
" %03d: %s\n"
, next->
getCode
(), next->
getText
());
102
pop
();
103
}
104
}
Generated on Tue Dec 25 2012 14:30:34 for My Project by
1.8.2