File: SylvException.cpp

package info (click to toggle)
dynare 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,640 kB
  • sloc: fortran: 82,231; cpp: 72,734; ansic: 28,874; pascal: 13,241; sh: 4,300; objc: 3,281; yacc: 2,833; makefile: 1,288; lex: 1,162; python: 162; lisp: 54; xml: 8
file content (69 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* $Header: /var/lib/cvs/dynare_cpp/sylv/cc/SylvException.cpp,v 1.2 2004/10/01 10:30:40 kamenik Exp $ */

/* Tag $Name:  $ */

#include "SylvException.h"

#include <cstring>
#include <cstdio>

SylvException::SylvException(const char* f, int l, const SylvException* s)
{
	strcpy(file,f);
	line = l;
	source = s;
}

SylvException::~SylvException()
{
	if (source != NULL) {
		delete source;
	}
}

void SylvException::printMessage() const
{
	char mes[1500];
	mes[0] = '\0';
	printMessage(mes, 1499);
	puts(mes);
}

int SylvException::printMessage(char* str, int maxlen) const
{
	int remain = maxlen;
	if (source != NULL) {
		remain = source->printMessage(str, maxlen);
	}
	char aux[100];
	sprintf(aux, "From %s:%d\n", file, line);
	int newremain = remain - strlen(aux);
	if (newremain < 0) {
		aux[remain] = '\0';
		newremain = 0;
	}
	strcat(str, aux);
	return newremain;
}

SylvExceptionMessage::SylvExceptionMessage(const char* f, int i,
										   const char* mes)
	: SylvException(f,i,NULL)
{
	strcpy(message,mes);
}

int SylvExceptionMessage::printMessage(char* str, int maxlen) const
{
	char aux[600];
	sprintf(aux, "At %s:%d:%s\n", file, line, message);
	int newremain = maxlen - strlen(aux);
	if (newremain < 0) {
		aux[maxlen] = '\0';
		newremain = 0;
	}
	strcat(str, aux);
	return newremain;
}