File: parser_exception.cpp

package info (click to toggle)
dynare 4.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 41,356 kB
  • ctags: 15,842
  • sloc: cpp: 77,029; ansic: 29,056; pascal: 13,241; sh: 4,811; objc: 3,061; yacc: 3,013; makefile: 1,479; lex: 1,258; python: 162; lisp: 54; xml: 8
file content (117 lines) | stat: -rw-r--r-- 2,532 bytes parent folder | download | duplicates (5)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (C) 2006, Ondra Kamenik

// $Id: parser_exception.cpp 2269 2008-11-23 14:33:22Z michel $

#include "parser_exception.h"
#include <cstring>
#include <cstdio>

using namespace ogp;

ParserException::ParserException(const char* m, int offset)
	: mes(new char[strlen(m)+1]), off(offset),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	strcpy(mes, m);
}

ParserException::ParserException(const string& m, int offset)
	: mes(new char[m.size()+1]), off(offset),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	strncpy(mes, m.c_str(), m.size());
	mes[m.size()] = '\0';
}

ParserException::ParserException(const string& m, const char* dum, int i1)
	: mes(new char[m.size()+1]), off(0),
	  aux_i1(i1), aux_i2(-1), aux_i3(-1)
{
	strncpy(mes, m.c_str(), m.size());
	mes[m.size()] = '\0';
}

ParserException::ParserException(const string& m, const char* dum, int i1, int i2) 
	: mes(new char[m.size()+1]), off(0),
	  aux_i1(i1), aux_i2(i2), aux_i3(-1)
{
	strncpy(mes, m.c_str(), m.size());
	mes[m.size()] = '\0';
}

ParserException::ParserException(const string& m, const char* dum, int i1, int i2, int i3) 
	: mes(new char[m.size()+1]), off(0),
	  aux_i1(i1), aux_i2(i2), aux_i3(i3)
{
	strncpy(mes, m.c_str(), m.size());
	mes[m.size()] = '\0';
}

ParserException::ParserException(const ParserException& m, int plus_offset)
	: mes(NULL),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	copy(m);
	off += plus_offset;
}

ParserException::ParserException(const ParserException& m, const char* dum, int i)
	: mes(NULL),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	copy(m);
	aux_i3 = m.aux_i2;
	aux_i2 = m.aux_i1;
	aux_i1 = i;
}

ParserException::ParserException(const ParserException& m, const char* dum, int i1, int i2)
	: mes(NULL),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	copy(m);
	aux_i3 = m.aux_i1;
	aux_i2 = i2;
	aux_i1 = i1;
}

ParserException::ParserException(const ParserException& m, const char* dum, int i1, int i2, int i3)
	: mes(NULL),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	copy(m);
	aux_i3 = i3;
	aux_i2 = i2;
	aux_i1 = i1;
}


ParserException::ParserException(const ParserException& e)
	: mes(NULL),
	  aux_i1(-1), aux_i2(-1), aux_i3(-1)
{
	copy(e);
} 

ParserException::~ParserException()
{
	delete [] mes;
}

void ParserException::copy(const ParserException& e)
{
	if (mes)
		delete [] mes;
	mes = new char[strlen(e.mes)+1];
	strcpy(mes, e.mes);
	off = e.off;
	aux_i1 = e.aux_i1;
	aux_i2 = e.aux_i2;
	aux_i3 = e.aux_i3;
}

void ParserException::print(FILE* fd) const
{
	// todo: to be refined
	fprintf(fd, "%s: offset %d\n", mes, off);
}