X


copyright = ""; // Open the input file to read the compiler // information database: ifstream in(argv[1]); if(!in) { error(string("can't...

Jak cię złapią, to znaczy, że oszukiwałeś. Jak nie, to znaczy, że posłużyłeś się odpowiednią taktyką.
find("#:" " :CompileDB.txt")
!= string::npos) {
Appendix A: Et cetera
997
// Parse the compiler information database:
CompilerData::readDB(in);
break; // Out of while loop
}
}
if(in.eof())
error("CompileDB.txt", "Can't find data");
in.seekg(0, ios::beg); // Back to beginning
map<string, Makefile> makeFiles;
while(getline(in, s)) {
// Look for tag at beginning of line:
if(s.find("//" ":") == 0
|| s.find("/*" ":") == 0
|| s.find("#" ":") == 0) {
CodeFile cf(in, s);
cf.write(); // Tell it to write itself
makeFiles[cf.path()].addEntry(cf);
}
}
// Write all the makefiles, telling each
// the path where it belongs:
map<string, Makefile>::iterator mfi;
for(mfi = makeFiles.begin();
mfi != makeFiles.end(); mfi++)
(*mfi).second.writeMakefiles((*mfi).first);
// Create the master makefile:
Makefile::writeMaster();
// Write the makefile that tries the bug files:
Makefile::writeMaster("bugs");
} ///:~
The first tool you see is trim( ), which was lifted from the strings chapter earlier in the book.
It removes the whitespace from both ends of a string object. This is followed by the usage string which is printed whenever something goes wrong with the program.
The error( ) function is global because it uses a trick with static members of functions.
error( ) is designed so that if it is never called, no error reporting occurs, but if it is called one or more times then an error file is created and the total number of errors is reported at the end of the program execution. This is accomplished by creating a nested class ErrReport and making a static ErrReport object inside error( ). That way, an ErrReport object is only created the first time error( ) is called, so if error( ) is never called no error reporting will occur. ErrReport creates an ofstream to write the errors to, and the ErrReport destructor closes the ofstream, then re-opens it and dumps it to cerr. This way, if the error report is too Appendix A: Et cetera
998
long and scrolls off the screen, you can use an editor to look at it. The count of the number of errors is held in ErrReport, and this is also reported upon program termination.
The job of a PushDirectory object is to capture the current directory, then created and move down each directory in the path (the path can be arbitrarily long). Each subdirectory in the
file’s path description is separated by a ‘:’ and the mkdir( ) and chdir( ) (or the equivalent on your system) are used to move into only one directory at a time, so the actual character that’s used to separate directory paths is safely ignored. The destructor returns the path to the one that was captured before all the creating and moving took place.
Unfortunately, there are no functions in Standard C or Standard C++ to control directory
creation and movement, so this is captured in the class OSDirControl. After reading the design patterns chapter, your first impulse might be to use the full “Bridge” pattern. However, there’s a lot more going on here. Bridge generally works with things that are already classes, and here we are actually creating the class to encapsulating operating system directory
control. In addition, this requires #ifdefs and #includes for each different operating system and compiler. However, the basic idea is that of a Bridge, since the rest of the code
(PushDirectory is actually the only thing that uses this, and thus it acts as the Bridge abstraction) treats an OsDirControl object as a standard interface.
All the information about a particular source code file is encapsulated in a CodeFile object.
This includes the type of target the file should produce, variations on the name of the file
Wątki
Powered by wordpress | Theme: simpletex | © Jak cię złapią, to znaczy, że oszukiwałeś. Jak nie, to znaczy, że posłużyłeś się odpowiednią taktyką.

Drogi uЕјytkowniku!

W trosce o komfort korzystania z naszego serwisu chcemy dostarczać Ci coraz lepsze usługi. By móc to robić prosimy, abyś wyraził zgodę na dopasowanie treści marketingowych do Twoich zachowań w serwisie. Zgoda ta pozwoli nam częściowo finansować rozwój świadczonych usług.

PamiД™taj, Ејe dbamy o TwojД… prywatnoЕ›Д‡. Nie zwiД™kszamy zakresu naszych uprawnieЕ„ bez Twojej zgody. Zadbamy rГіwnieЕј o bezpieczeЕ„stwo Twoich danych. WyraЕјonД… zgodД™ moЕјesz cofnД…Д‡ w kaЕјdej chwili.

 Tak, zgadzam siД™ na nadanie mi "cookie" i korzystanie z danych przez Administratora Serwisu i jego partnerГіw w celu dopasowania treЕ›ci do moich potrzeb. PrzeczytaЕ‚em(am) PolitykД™ prywatnoЕ›ci. Rozumiem jД… i akceptujД™.

 Tak, zgadzam siД™ na przetwarzanie moich danych osobowych przez Administratora Serwisu i jego partnerГіw w celu personalizowania wyЕ›wietlanych mi reklam i dostosowania do mnie prezentowanych treЕ›ci marketingowych. PrzeczytaЕ‚em(am) PolitykД™ prywatnoЕ›ci. Rozumiem jД… i akceptujД™.

Wyrażenie powyższych zgód jest dobrowolne i możesz je w dowolnym momencie wycofać poprzez opcję: "Twoje zgody", dostępnej w prawym, dolnym rogu strony lub poprzez usunięcie "cookies" w swojej przeglądarce dla powyżej strony, z tym, że wycofanie zgody nie będzie miało wpływu na zgodność z prawem przetwarzania na podstawie zgody, przed jej wycofaniem.