"Doxygenizer.h" : #Include #Include #Include
"Doxygenizer.h" : #Include #Include #Include
"Doxygenizer.h" : #Include #Include #Include
/*!
\file Screenshake.cs
\author Khan Sweetman
\par All content 2015 DigiPen (USA) Corporation, all rights reserved.
\brief
File does does things. COOL things.
*/
/*******************************************************************************/
#include "Doxygenizer.h"
#include <stdio.h>
#include <string.h>
// Syntactic shortcuts
using std::cout;
using std::cin;
using std::endl;
using std::string;
Doxygenizer::Doxygenizer() : bracesIn(0)
{
// ...
}
Doxygenizer::~Doxygenizer()
{
// ...
}
void Doxygenizer::LoadFile(std::string fileName)
{
// Open the file
m_fileName = fileName;
m_inStream.open(fileName.c_str());
m_outStream.open("temp.txt");
// Check for validity
if (m_inStream.is_open())
{
std::cout << "Opening " << fileName << "..." << std::endl;
std::string fileEnding = fileName.substr(m_fileName.size() - 3, m_fileName.size()).c_str();
if(!HeaderAlreadyDefined())
{
std::cout << "Inserting header..." << std::endl;
if(strcmp(fileEnding.c_str(), "cpp") == 0)
InsertImplementationFileHeader();
else
InsertInterfaceFileHeader();
}
// Copy the file into a temporary file, generate headers along the way
std::cout << "Processing file " << fileName << "..." << std::endl;
std::vector<std::string> lines;
std::string workingLine;
while(!m_inStream.eof())
{
std::getline(m_inStream, workingLine);
lines.push_back(workingLine);
// Check for reasons to insert Doxy comments
if(IsFunctionBeginning(workingLine))
{
// Dump all but the last two stored lines
for(unsigned i = 0; i < lines.size() - 2; ++i)
m_outStream << lines[i] << std::endl;
// Then write the header
InsertFunctionHeader(lines[lines.size() - 2]);
// Then insert the last two lines for proper alignment
m_outStream << lines[lines.size() - 2] << std::endl;
m_outStream << lines[lines.size() - 1] << std::endl;
lines.clear();
}
}
// Dump out any remaining lines
for(unsigned i = 0; i < lines.size() - 1; ++i)
m_outStream << lines[i] << std::endl;
CopyFileBack();
}
// Tell the user that the file can't be opened
else
{
std::cout << "Can't open file." << std::endl;
}
std::cout << "Closing file" << fileName << "..." << std::endl << std::endl;
m_inStream.close();
m_outStream.close();
void Doxygenizer::CopyFileBack()
{
m_inStream.close();
m_inStream.open("temp.txt");
m_outStream.close();
m_outStream.open(m_fileName.c_str());
while(!m_inStream.eof())
{
std::string line;
std::getline(m_inStream, line);
m_outStream << line << std::endl;
}
return false;
bool Doxygenizer::HeaderAlreadyDefined()
{
std::ifstream headerStream(m_fileName.c_str());
std::string firstLine;
std::getline(headerStream, firstLine);
bool alreadyDefined = false;
if(strcmp(firstLine.c_str(),
"/*******************************************************************************/") == 0)
alreadyDefined = true;
headerStream.close();
return alreadyDefined;
}
void Doxygenizer::InsertFunctionHeader(std::string headerLine)
{
// Get the parameters
// - Doesn't work with function pointer return types, unless they are typdef'd first
// - Doesn't work if there are extra spaces
// - Doesn't work with const
int numSpaces = 0;
size_t pos = headerLine.find_first_of("(");
size_t prevPos = pos;
std::vector<std::string> parameters;
bool onParam = false;
while(headerLine.find_first_of(" ", pos) != string::npos)
{
++numSpaces;
pos = headerLine.find_first_of(" ", pos + 1);
if(onParam)
parameters.push_back(headerLine.substr(prevPos + 1, pos - 2));
onParam = !onParam;
prevPos = pos;
}
// Get the return type
size_t index = headerLine.find_first_of(" ");
std::string returnType = headerLine.substr(0, index + 1);
m_outStream <<
"/******************************************************************************/\n";
m_outStream << "/*!\n";
m_outStream << "\\brief\n";
m_outStream << " \n";
m_outStream << " \n";
// Print the parameters
for(unsigned i = 0; i < parameters.size(); ++i)
{
m_outStream << "\\param " << parameters[i].c_str() << "\n";
//std::cout << parameters[i].c_str() << std::endl;
m_outStream << " \n";
m_outStream << "\n";
}
// Print the return type
if(strcmp(returnType.c_str(), "void") != 0)
{
m_outStream << "\\return\n";
m_outStream << " \n";
}
m_outStream << "*/\n";
m_outStream <<
"/******************************************************************************/\n";
return;
}
std::string Doxygenizer::GetDate()
{
// Get the current date/time
time_t rawTime;
struct tm * timeInfo;
time(&rawTime);
timeInfo = localtime(&rawTime);
string date = string(asctime(timeInfo)).substr(0, 11) + string(asctime(timeInfo)).substr(20, 24);
return date;