Monday, May 06, 2013

Cute coding trick...

In building cars and planes and rockets, I collect a lot of data log files for all of the projects....
I backup all the source files using source control on every build..., but I presently had no way to connect a data file to the exact source that was used to make it...  I'm sure this has been done a thousand times... before but I reinvented the wheel last night...
I wrote a simple  header file...

call it FileList.h

//A Class to make a static linked list of ALL files included in the project....

class FileList
{
private:
static FileList * pHead;
FileList * m_pNext;
const char * m_pName;
public:
//The constructor will add the name to the global static linked list...
FileList(const char * name)
{m_pNext=pHead;
  pHead=this,
  m_pName=name;
};

static void ShowList();
};

//A Static opbject that does the real work...
//__BASE_FILE__ is the name of the file being compiled rather thatn this header file
static FileList FL(__DATE__ "," __TIME__ "," __BASE_FILE__);



If you #include "filelist.h"
in every single C++ file in your project... this will make a linked list of
all the file names, dates and times..... a list I can prepend to the data log on startup...
so now the whole code set and its date time are included in the data log on every start...

Maybe this is common knowledge, but the __BASE__FILE__ macro was a new one to me...