Made some modifications in LineInformation class
[dyninst.git] / dyninstAPI / src / BPatch_sourceBlock.C
1 #define BPATCH_FILE
2
3 #include <stdio.h>
4 #include <iostream.h>
5 #include "BPatch_sourceBlock.h"
6
7 //constructor
8 BPatch_sourceBlock::BPatch_sourceBlock()
9         : sourceFile(NULL),sourceLines(NULL)
10 {}
11
12 //constructor
13 BPatch_sourceBlock::BPatch_sourceBlock(
14         const char* filePtr,BPatch_Set<unsigned short>& lines)
15 {
16         sourceFile = filePtr;
17         sourceLines = new BPatch_Set<unsigned short>(lines);
18 }
19
20 const char*
21 BPatch_sourceBlock::getSourceFile(){
22         return sourceFile;
23 }
24
25 void
26 BPatch_sourceBlock::getSourceLines(BPatch_Vector<unsigned short>& lines){
27
28         if(!sourceLines)
29                 return;
30
31         unsigned short* elements = new unsigned short[sourceLines->size()];
32         sourceLines->elements(elements);
33
34         for(int j=0;j<sourceLines->size();j++)
35                 lines.push_back(elements[j]);
36                 
37         delete[] elements;
38 }
39
40
41 //print method 
42 ostream& operator<<(ostream& os,BPatch_sourceBlock& sb){
43
44         os << "{";
45
46         if(sb.sourceFile)
47                 os << sb.sourceFile << " (";
48         else
49                 os << "<NO_FILE_NAME>" << " (";
50                 
51         if(sb.sourceLines){
52                 unsigned short* elements = new unsigned short[sb.sourceLines->size()];
53                 sb.sourceLines->elements(elements);
54                 for(int j=0;j<sb.sourceLines->size();j++)
55                         os << " " << elements[j];
56                 delete[] elements;
57         }
58         else
59                 os << "<NO_LINE_NUMBERS>";
60
61         os << ")}" << endl;
62         return os;
63 }