File: GrpLineAndFile.hpp

package info (click to toggle)
grcompiler 4.2-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 11,108 kB
  • sloc: cpp: 45,565; sh: 4,425; ansic: 4,377; makefile: 188; xml: 175; perl: 127
file content (124 lines) | stat: -rw-r--r-- 2,932 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
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
118
119
120
121
122
123
124
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: GrpLineAndFile.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
    A simple class to hold the line number and file name for tokens and objects.
-------------------------------------------------------------------------------*//*:End Ignore*/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef LINENFILE_INCLUDED
#define LINENFILE_INCLUDED

#include <iostream>

class GrpLineAndFile	// hungarian: lnf (line-n-file)
{
public:
	//	Constructors:
	GrpLineAndFile()
		:	m_nLinePre(-1),
			m_nLineOrig(-1)
	{
	}

	GrpLineAndFile(int nPre, int nOrig, std::string sta)
		:	m_nLinePre(nPre),
			m_nLineOrig(nOrig),
			m_staFile(sta)
	{
	}

	//	copy constructor
	GrpLineAndFile(const GrpLineAndFile & lnf)
	{
		m_nLinePre = lnf.m_nLinePre;
		m_nLineOrig = lnf.m_nLineOrig;
		m_staFile = lnf.m_staFile;
	}

	~GrpLineAndFile()
	{
	}

	GrpLineAndFile & operator=(const GrpLineAndFile & lnf)
	{
		m_nLinePre = lnf.m_nLinePre;
		m_nLineOrig = lnf.m_nLineOrig;
		m_staFile = lnf.m_staFile;
		return *this;
	}

	//	Getters and setters:
	int PreProcessedLine() const	{ return m_nLinePre; };
	int OriginalLine() const		{ return m_nLineOrig; }
	std::string File() const		{ return m_staFile; }

	void SetOriginalLine(int n)		{ m_nLineOrig = n; }
	void SetPreProcessedLine(int n)	{ m_nLinePre = n; }
	void SetFile(std::string sta)	{ m_staFile = sta; }

	void CopyLineAndFile(GrpLineAndFile & lnf)
	{
		m_nLinePre = lnf.m_nLinePre;
		m_nLineOrig = lnf.m_nLineOrig;
		m_staFile = lnf.m_staFile;
	}

	bool NotSet()
	{
		return m_nLinePre == -1;
	}

	bool operator==(GrpLineAndFile & lnf)
	{
		if (m_nLinePre == 0 && lnf.m_nLinePre == 0)
			return (m_nLineOrig == lnf.m_nLineOrig);	// eg, preprocessor errors
		else
			return m_nLinePre == lnf.m_nLinePre;
	}

	bool operator<(GrpLineAndFile & lnf)
	{
		if (m_nLinePre == 0 && lnf.m_nLinePre == 0)
			return (m_nLineOrig < lnf.m_nLineOrig);	// eg, preprocessor errors
		else
			return m_nLinePre < lnf.m_nLinePre;
	}

	void WriteToStream(std::ostream & strmOut, bool fNoPath)
	{
		int ich = m_staFile.length();
		// Strip off the file path.
		while (fNoPath && ich > 0 && m_staFile[ich - 1] != '\\')
			ich--;

		std::string staStripped = m_staFile.substr(ich, m_staFile.length() - ich);
		strmOut << staStripped << "(" << m_nLineOrig << ")";
	}

protected:
	//	instance variables:
	int m_nLinePre;			// line in pre-processed file
	int	m_nLineOrig;		// actual line in original file
	std::string m_staFile;		// original file name

public:
	//	for test procedures:
	void test_SetLineNumbers(int n)
	{
		m_nLinePre = n;
		m_nLineOrig = n;
	}
};


#endif // !LINENFILE_INCLUDED