Member variables and methods
|Top Previous Next|
Now some variables and methods shall be presented, which are defined on the element page.
The positions of the URL's in the texts shall be collected in a member variable of the type mstrstr:
The key shall be the found URL itself, and the value will be constructed out of the name of the actual file and the according line number. These can be obtained from methods of the parser:
SourceName() name of the actual file
xState.Line() line number
A variable of the type format shall help, to combine the names and the numbers into one string:
By the command:
m_fPosition.parse(" Page: %|1$|%|50t|Line: %|2$|");
m_fPosition is initialized with the formatting string " Page: %|1$|%|50t|Line: %|2$|".
"%|1$|" represents the position of the first argument,%|2$| represents the second argument and by %|50t| the preceding part of text is padded with spaces to a length of 50 characters. If e.g the file name is "D:\C_biblio\boost\index.htm" and the line number is 52, and both are passed to the format object by means of the %-operator, this object returns:
" Page: D:\C_biblio\boost\index.htm Line: 52"
To avoid very long file names, they shall be expressed in a shorter form with relative paths. For this a special method is defined in the project, which transforms the absolute paths, which are obtained by SourceName() to relative paths:
return ".." + SourceName().substr(SourceRoot().length());
This function consists in only one line. What happens here becomes clear, when it is separated into several steps:
str sDir = SourceRoot();
unsigned int pos = sRoot.length();
str sAbsFilename = SourceName();
str sPart = sAbsFilename.substr(pos);
str sRelFilename = ".." + sPart;
The resulting relative file name begins with "..", followed by the part of the absolute file name, which follows on the string, which designates the source directory. For "D:\C_biblio\boost\index.htm" and the source directory "D:\C_biblio\boost" this results in:
A further method defined on the element page is AddPosition, which is called with the parameters of an URL xsUrl and the position xsWhere:
m_mUrl[xsUrl] += "\n" + xsWhere;
m_mUrl[xsUrl] = xsWhere;
This method takes into account, that there may be several positions for the same URL. If the URL hasn't been found yet the position will be set as value of the URL key in the else-branch. If the URL has been found before, the new position text is simply appended to the old value.
Before the program ends, m_mUrl will be printed by the function PrintAll. Hereby all internet addresses will appear in alphabetical order automatically:
out << m_mUrl.key() << endl;
out << m_mUrl.value() << endl << endl;
This page belongs to the TextTransformer Documentation
|Home Content German|