| 1364 | } |
| 1365 | |
| 1366 | void ClassCompiler::CompileFile(const std::string& inputpath, |
| 1367 | const std::string& implpath, const std::string& headerpath) |
| 1368 | { |
| 1369 | std::ifstream input; |
| 1370 | input.open(inputpath.c_str(), std::ifstream::in); |
| 1371 | |
| 1372 | if (!input) { |
| 1373 | std::cerr << "Could not open input file: " << inputpath << std::endl; |
| 1374 | std::exit(EXIT_FAILURE); |
| 1375 | } |
| 1376 | |
| 1377 | std::string tmpheaderpath = headerpath + ".tmp"; |
| 1378 | std::ofstream oheader; |
| 1379 | oheader.open(tmpheaderpath.c_str(), std::ofstream::out); |
| 1380 | |
| 1381 | if (!oheader) { |
| 1382 | std::cerr << "Could not open header file: " << tmpheaderpath << std::endl; |
| 1383 | std::exit(EXIT_FAILURE); |
| 1384 | } |
| 1385 | |
| 1386 | std::string tmpimplpath = implpath + ".tmp"; |
| 1387 | std::ofstream oimpl; |
| 1388 | oimpl.open(tmpimplpath.c_str(), std::ofstream::out); |
| 1389 | |
| 1390 | if (!oimpl) { |
| 1391 | std::cerr << "Could not open implementation file: " << tmpimplpath << std::endl; |
| 1392 | std::exit(EXIT_FAILURE); |
| 1393 | } |
| 1394 | |
| 1395 | CompileStream(inputpath, input, oimpl, oheader); |
| 1396 | |
| 1397 | input.close(); |
| 1398 | oimpl.close(); |
| 1399 | oheader.close(); |
| 1400 | |
| 1401 | #ifdef _WIN32 |
| 1402 | _unlink(headerpath.c_str()); |
| 1403 | #endif /* _WIN32 */ |
| 1404 | |
| 1405 | if (rename(tmpheaderpath.c_str(), headerpath.c_str()) < 0) { |
| 1406 | std::cerr << "Could not rename header file: " << tmpheaderpath << " -> " << headerpath << std::endl; |
| 1407 | std::exit(EXIT_FAILURE); |
| 1408 | } |
| 1409 | |
| 1410 | #ifdef _WIN32 |
| 1411 | _unlink(implpath.c_str()); |
| 1412 | #endif /* _WIN32 */ |
| 1413 | |
| 1414 | if (rename(tmpimplpath.c_str(), implpath.c_str()) < 0) { |
| 1415 | std::cerr << "Could not rename implementation file: " << tmpimplpath << " -> " << implpath << std::endl; |
| 1416 | std::exit(EXIT_FAILURE); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | std::string ClassCompiler::BaseName(const std::string& path) |
| 1421 | { |