Added TemplateCompiler project and sharedTemplate/sharedTemplateDefinition libraries

This commit is contained in:
Anonymous
2014-01-21 10:31:25 -07:00
parent 232bcc82dc
commit 9ecd34c0ab
249 changed files with 49504 additions and 0 deletions
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8)
project(sharedTemplateDefinition)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
add_subdirectory(src)
@@ -0,0 +1,2 @@
#include "../../src/shared/core/CompilerDynamicVariableParamData.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/CompilerIntegerParam.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/File.h"
@@ -0,0 +1 @@
#include "../../src/shared/core/Filename.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/FirstSharedTemplateDefinition.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/ObjectTemplate.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/TemplateData.h"
@@ -0,0 +1 @@
#include "../../src/shared/core/TemplateDataIterator.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/TemplateDefinitionFile.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/TemplateGlobals.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/TpfFile.h"
@@ -0,0 +1,2 @@
#include "../../src/shared/core/TpfTemplate.h"
@@ -0,0 +1,57 @@
set(SHARED_SOURCES
shared/core/CompilerDynamicVariableParamData.cpp
shared/core/CompilerDynamicVariableParamData.h
shared/core/CompilerIntegerParam.cpp
shared/core/CompilerIntegerParam.h
shared/core/File.cpp
shared/core/File.h
shared/core/Filename.cpp
shared/core/Filename.h
shared/core/FirstSharedTemplateDefinition.h
shared/core/ObjectTemplate.cpp
shared/core/ObjectTemplate.h
shared/core/TemplateData.cpp
shared/core/TemplateData.h
shared/core/TemplateDataIterator.cpp
shared/core/TemplateDataIterator.h
shared/core/TemplateDefinitionFile.cpp
shared/core/TemplateDefinitionFile.h
shared/core/TemplateGlobals.cpp
shared/core/TemplateGlobals.h
shared/core/TpfFile.cpp
shared/core/TpfFile.h
shared/core/TpfTemplate.cpp
shared/core/TpfTemplate.h
)
if(WIN32)
set(PLATFORM_SOURCES
win32/FirstSharedTemplateDefinition.cpp
)
else()
set(PLATFORM_SOURCES
linux/FirstSharedTemplateDefinition.cpp
)
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/shared/core
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRandom/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRegex/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedUtility/include/public
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localization/include
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include
${PCRE_INCLUDE_DIR}
)
add_library(sharedTemplateDefinition STATIC
${SHARED_SOURCES}
${PLATFORM_SOURCES}
)
@@ -0,0 +1 @@
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
@@ -0,0 +1,38 @@
//========================================================================
//
// CompilerDynamicVariableParamData.cpp -
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "sharedTemplateDefinition/CompilerDynamicVariableParamData.h"
#include "sharedTemplateDefinition/CompilerIntegerParam.h"
/**
* Class constructor.
*
* @param name variable name
* @param type variable type
*/
CompilerDynamicVariableParamData::CompilerDynamicVariableParamData(
const std::string &name, DynamicVariableParamData::DataType type) :
DynamicVariableParamData(name, type)
{
if (type == DynamicVariableParamData::INTEGER)
{
delete m_data.iparam;
m_data.iparam = new CompilerIntegerParam();
}
} // CompilerDynamicVariableParamData::CompilerDynamicVariableParamData
/**
* Class destructor.
*/
CompilerDynamicVariableParamData::~CompilerDynamicVariableParamData()
{
} // CompilerDynamicVariableParamData::~CompilerDynamicVariableParamData
@@ -0,0 +1,28 @@
//========================================================================
//
// CompilerDynamicVariableParamData.h - Adds additional functionality to the IntegerParam
// class for the template compiler/editor.
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_CompilerDynamicVariableParamData_H
#define _INCLUDED_CompilerDynamicVariableParamData_H
#include "sharedUtility/TemplateParameter.h"
class CompilerDynamicVariableParamData : public DynamicVariableParamData
{
public:
CompilerDynamicVariableParamData(const std::string &name, DynamicVariableParamData::DataType type);
virtual ~CompilerDynamicVariableParamData();
private:
CompilerDynamicVariableParamData(const CompilerDynamicVariableParamData &);
CompilerDynamicVariableParamData & operator =(const CompilerDynamicVariableParamData &);
};
#endif // _INCLUDED_CompilerDynamicVariableParamData_H
@@ -0,0 +1,19 @@
//========================================================================
//
// CompilerIntegerParam.cpp - Adds additional functionality to the IntegerParam
// class for the template compiler/editor.
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "sharedTemplateDefinition/CompilerIntegerParam.h"
/**
* Class destructor.
*/
CompilerIntegerParam::~CompilerIntegerParam()
{
} // CompilerIntegerParam::~CompilerIntegerParam
@@ -0,0 +1,50 @@
//========================================================================
//
// CompilerIntegerParam.h - Adds additional functionality to the IntegerParam
// class for the template compiler/editor.
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_CompilerIntegerParam_H
#define _INCLUDED_CompilerIntegerParam_H
#include "sharedUtility/TemplateParameter.h"
#include <string>
#include <vector>
class CompilerIntegerParam : public IntegerParam
{
public:
CompilerIntegerParam(void);
virtual ~CompilerIntegerParam();
void addSourceEnumList(std::vector<std::string> & enumList);
const std::vector<std::string> & getSourceEnumList(void);
private:
std::vector<std::string> m_enumList; // list of enum names used to
// create this param
};
inline CompilerIntegerParam::CompilerIntegerParam(void) : IntegerParam()
{
}
inline void CompilerIntegerParam::addSourceEnumList(std::vector<std::string> & enumList)
{
std::swap(m_enumList, enumList);
}
inline const std::vector<std::string> & CompilerIntegerParam::getSourceEnumList(void)
{
return m_enumList;
}
#endif // _INCLUDED_CompilerIntegerParam_H
@@ -0,0 +1,188 @@
//========================================================================
//
// File.cpp - file reader/writer
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "File.h"
#include "TemplateGlobals.h"
#ifdef WIN32
#include <share.h>
#endif
//========================================================================
// File static variables
Filename File::m_basePath;
File::FunctionPtr File::m_callBack = NULL;
//========================================================================
// File functions
/**
* Opens a file for reading or writing.
*
* @param filename name of file to open (relative to base path)
* @param mode read/write mode, see fopen()
*
* @return true if the file was opened, false if not
*/
bool File::open(const char *filename, const char *mode)
{
NOT_NULL(filename);
NOT_NULL(mode);
close();
m_filename.clear();
m_filename.setName(filename);
m_filename.prependPath(m_basePath);
#ifdef WIN32
m_fp = _fsopen(m_filename, mode, _SH_DENYRW);
#else
// @todo: find an equivalent function for Linux
m_fp = fopen(m_filename, mode);
#endif
if (m_fp != NULL)
{
m_currentLine = 0;
return true;
}
else
{
const char * errstr = strerror(errno);
if (errstr != NULL)
{
m_filename.clear();
printError(errstr);
}
}
return false;
} // File::open
/**
* Tests if a file exists.
*
* @param filename the file to test
*
* @return true if the file exists, false if not
*/
bool File::exists(const char *filename)
{
if (filename == NULL)
return false;
#if defined(WIN32)
DWORD attributes = GetFileAttributes(filename);
#if _MSC_VER < 1300
const DWORD INVALID_FILE_ATTRIBUTES = 0xffffffff;
#endif
return (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
#elif defined(linux)
return FileExists(filename);
#else
return false;
#endif
} // File::exists
/**
* Reads the next line of a file.
*
* @param fp file to read from
* @param buffer buffer to read the line in to
* @param bufferSize size of buffer
*
* @return the size of the string, or -1 on eof or -2 on error
*/
int File::readRawLine(char *buffer, int bufferSize)
{
NOT_NULL(m_fp);
NOT_NULL(buffer);
++m_currentLine;
if (fgets(buffer, bufferSize, m_fp) == NULL)
{
if (feof(m_fp))
return -1;
else
{
printError("error reading file.");
return -2;
}
}
// if buffer doen't end in '\n', the line is too long
if (static_cast<int>(strlen(buffer)) == bufferSize - 1 &&
buffer[bufferSize - 2] != '\n')
{
printError("line too long");
return -2;
}
return strlen(buffer);
} // File::readRawLine
/**
* Reads the next line of a file, strips leading and trailing whitespace.
*
* @param fp file to read from
* @param buffer buffer to read the line in to
* @param bufferSize size of buffer
*
* @return the size of the string, or -1 on eof or -2 on error
*/
int File::readLine(char *buffer, int bufferSize)
{
NOT_NULL(m_fp);
NOT_NULL(buffer);
for (;;)
{
++m_currentLine;
if (fgets(buffer, bufferSize, m_fp) == NULL)
{
if (feof(m_fp))
return -1;
else
{
printError("error reading file.");
return -2;
}
}
// if buffer doen't end in '\n', the line is too long
if (static_cast<int>(strlen(buffer)) == bufferSize - 1 &&
buffer[bufferSize - 2] != '\n')
{
printError("line too long");
return -2;
}
int length = strip(buffer);
if (length != 0)
return length;
}
} // File::readLine
/**
* fprintf functionality.
*/
int File::print(const char *format, ...)
{
NOT_NULL(m_fp);
va_list argptr;
va_start(argptr, format);
return vfprintf(m_fp, format, argptr);
} // File::print
@@ -0,0 +1,144 @@
//========================================================================
//
// File.h - file reader/writer
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_File_H
#define _INCLUDED_File_H
#include "Filename.h"
#include <cstdio>
class File
{
public:
explicit File(void);
explicit File(const char *filename, const char *mode);
~File();
static void setBasePath(const char *path);
const Filename & getFilename(void) const;
bool isOpened(void) const;
bool open(const char *filename, const char *mode);
void close(void);
bool exists(const char *filename);
int readRawLine(char *buffer, int bufferSize);
int readLine(char *buffer, int bufferSize);
int puts(const char *string);
int print(const char *format, ...);
void printWarning(const char *buffer) const;
void printError(const char *buffer) const;
void printEolError(void) const;
typedef void (* FunctionPtr)(const char *error);
static void setErrorCallBack(FunctionPtr callBack);
private:
FILE *m_fp; // file being read from
Filename m_filename; // name of file being read
int m_currentLine; // current line being read
static FunctionPtr m_callBack;
static Filename m_basePath; // path all files will be opened relative to
};
inline File::File(void) :
m_fp(NULL),
m_currentLine(0)
{
} // File::File(void)
inline File::File(const char *filename, const char *mode) :
m_fp(NULL),
m_currentLine(0)
{
open(filename, mode);
} // File::File(const char *)
inline File::~File()
{
close();
} // File::~File
inline void File::setBasePath(const char *path)
{
m_basePath.setPath(path);
} // File::setBasePath
inline const Filename & File::getFilename(void) const
{
return m_filename;
} // File::getFilename
inline bool File::isOpened(void) const
{
return (m_fp != NULL);
} // File::isOpened
inline void File::close(void)
{
if (m_fp != NULL)
{
fclose(m_fp);
m_fp = NULL;
}
} // File::close
inline int File::puts(const char *string)
{
NOT_NULL(m_fp);
return fputs(string, m_fp);
} // File::puts
inline void File::printWarning(const char *buffer) const
{
NOT_NULL(buffer);
char error[4096];
sprintf(error, "WARNING file <%s> line %d: %s\n", m_filename.getName().c_str(), m_currentLine, buffer);
fprintf(stderr, "%s", error);
if (m_callBack != NULL)
{
m_callBack(error);
}
} // File::printWarning
inline void File::printError(const char *buffer) const
{
NOT_NULL(buffer);
char error[4096];
sprintf(error, "ERROR file <%s> line %d: %s\n", m_filename.getName().c_str(), m_currentLine, buffer);
fprintf(stderr, "%s", error);
if (m_callBack != NULL)
{
m_callBack(error);
}
} // File::printError
inline void File::printEolError(void) const
{
printError("unexpected end of line");
} // File::printEolError
inline void File::setErrorCallBack(FunctionPtr callBack)
{
m_callBack = callBack;
} // File::setErrorCallBack
#endif // _INCLUDED_File_H
@@ -0,0 +1,392 @@
//========================================================================
//
// Filename.cpp - a fully qualified file name
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "Filename.h"
#include "TemplateGlobals.h"
#include "UnicodeUtils.h"
#if defined(PLATFORM_LINUX)
#include <libgen.h>
#endif
const char WIN32_PATH_SEPARATOR = '\\';
const char LINUX_PATH_SEPARATOR = '/';
//#if defined(WIN32)
//const char PATH_SEPARATOR = WIN32_PATH_SEPARATOR;
//#elif defined(linux)
const char PATH_SEPARATOR = LINUX_PATH_SEPARATOR;
//#else
//#error unknown OS
//#endif
/**
* Sets the path of the file name.
* If the path has a drive letter, the drive will be set (Winodws only)
*
* @param path the path
*/
void Filename::setPath(const char *path)
{
if (path == NULL || *path == '\0')
m_path = "";
else
{
#ifdef WIN32
if (isalpha(*path) && *(path + 1) == ':')
{
setDrive(path);
path += 2;
}
#endif
m_path = path;
convertToSystemPath(m_path);
if (m_path[strlen(path) - 1] != PATH_SEPARATOR)
m_path += PATH_SEPARATOR;
}
makeFullPath();
} // Filename::setPath
/**
* Sets the name of the file name.
* If the name has an extension, the extension will be set
* If the name has a full path (starts with drive or separator), the path will be set
* If the name has a relative path, the path will be appended to the current path
*
* @param name the name
*/
void Filename::setName(const char *name)
{
if (name == NULL || *name == '\0')
m_name = "";
else
{
#ifdef WIN32
if (isalpha(*name) && *(name + 1) == ':')
{
setDrive(name);
name += 2;
}
#endif
std::string localname = name;
convertToSystemPath(localname);
const char *dot = strrchr(localname.c_str(), '.');
const char *firstSeparator = strchr(localname.c_str(), PATH_SEPARATOR);
const char *lastSeparator = strrchr(localname.c_str(), PATH_SEPARATOR);
if (firstSeparator != NULL)
{
// name has a path
if (firstSeparator == localname)
{
// set path
m_path = std::string(firstSeparator, lastSeparator - firstSeparator + 1);
}
else
{
// append path
m_path += std::string(localname.c_str(), lastSeparator -
localname.c_str() + 1);
}
}
if (dot != NULL && (lastSeparator == NULL || dot > lastSeparator))
{
// name has an extension
setExtension(dot);
if (lastSeparator == NULL)
m_name = std::string(localname.c_str(), dot - localname.c_str());
else
m_name = std::string(lastSeparator + 1, dot - (lastSeparator + 1));
}
else
{
// name doesn't have an extension
if (lastSeparator == NULL)
m_name = localname;
else
m_name = std::string(lastSeparator + 1);
}
}
makeFullPath();
} // Filename::setName
/**
* Sets the extension of the file name.
*
* @param path the path
*/
void Filename::setExtension(const char *extension)
{
if (extension == NULL || *extension == '\0')
m_extension = "";
else
{
if (*extension == '.')
m_extension = extension;
else
{
m_extension = ".";
m_extension += extension;
}
}
makeFullPath();
} // Filename::setExtension
/**
* Converts a path name to use the system path seperator.
*
* @param path the path to convert
*/
void Filename::convertToSystemPath(std::string & path)
{
size_t i;
std::string newpath;
size_t count = path.size();
for (i = 0; i < count; ++i)
{
if (path[i] == '/' || path[i] == '\\')
{
if (newpath.empty() || newpath[newpath.size() - 1] != PATH_SEPARATOR)
newpath += PATH_SEPARATOR;
}
else
newpath += path[i];
}
path = newpath;
} // Filename::convertToSystemPath
/**
* Prepends a path to our path, unless our path is an an absolute path.
*
* @param path the path to prepend
*/
void Filename::prependPath(const Filename &path)
{
if (m_path.size() != 0 && m_path[0] != PATH_SEPARATOR)
{
m_path = path.getPath() + m_path;
convertToSystemPath(m_path);
makeFullPath();
}
} // Filename::prependPath
/**
* Appends a path to our path. If the path is an absolute path, replaces our path.
*
* @param path the path to append
*/
void Filename::appendPath(const Filename &path)
{
std::string localpath = path.getPath();
convertToSystemPath(localpath);
if (localpath.size() != 0 && localpath[0] == PATH_SEPARATOR)
m_path = localpath;
else
m_path += localpath;
makeFullPath();
} // Filename::appendPath
/**
* Converts paths like A/./B to A/B and A/B/../C to A/C.
*/
void Filename::normalizePath(void)
{
static const char PATH_SEPARATOR_BUFF[] = {PATH_SEPARATOR, '\0'};
static const std::string PATH_SEPARATOR_STRING(PATH_SEPARATOR_BUFF);
// get rid of "/./"
std::string mask(PATH_SEPARATOR_STRING + "." + PATH_SEPARATOR_STRING);
std::string::size_type pos;
for (pos = m_path.find(mask); pos != std::string::npos; pos = m_path.find(mask))
{
m_path.erase(pos, mask.size() - 1);
}
// get rid of "/../"
mask = PATH_SEPARATOR_STRING + ".." + PATH_SEPARATOR_STRING;
std::string::size_type startPos = 0;
for (pos = m_path.find(mask, startPos); pos != std::string::npos;
pos = m_path.find(mask, startPos))
{
if (pos != 0)
{
std::string::size_type prevPathPos = m_path.rfind(PATH_SEPARATOR, pos - 1);
if (prevPathPos == 0)
{
m_path.erase(0, pos + mask.size() - 1);
}
else if (prevPathPos == std::string::npos || m_path.substr(prevPathPos,
pos - prevPathPos + 1) == mask)
{
startPos = pos + 1;
}
else
{
m_path.erase(prevPathPos + 1, (pos + mask.size() - 1) - prevPathPos);
}
}
else
{
m_path.erase(pos, mask.size() - 1);
}
}
} // Filename::normalizePath
/**
* Sets the drive letter of the file name.
*
* @param drive the drive
*/
void Filename::setDrive(const char *drive)
{
if (drive != NULL && isalpha(*drive))
m_drive = std::string(drive, 1) + ":";
else
m_drive = "";
makeFullPath();
} // Filename::setDrive
/**
* Determines the absolute path (including drive letter for Windows) for the
* current path.
*
* @return the absolute path
*/
const std::string Filename::getAbsolutePath(void) const
{
std::string path;
#if defined(WIN32)
char *pathBuf;
DWORD bufsize = GetFullPathName(getFullFilename().c_str(), 0, NULL, NULL);
if (bufsize != 0)
{
pathBuf = new char[bufsize + 1];
char * filenamePart;
GetFullPathName(getFullFilename().c_str(), bufsize + 1, pathBuf, &filenamePart);
*filenamePart = '\0';
path = pathBuf;
delete[] pathBuf;
}
#elif defined(linux)
char pathBuf[PATH_MAX];
if (getcwd(pathBuf, PATH_MAX) != NULL)
{
strcat(pathBuf, "/");
strcat(pathBuf, getFullFilename().c_str());
dirname(pathBuf);
strcat(pathBuf, "/");
path = pathBuf;
}
#endif
return path;
} // Filename::getAbsolutePath
/**
* Makes sure the path of the filename exists. If it doesn't, create the path.
*/
void Filename::verifyAndCreatePath(void) const
{
#if defined(WIN32)
if (WindowsUnicode)
{
char *buffer = NULL;
DWORD buflen;
// get our current path
buflen = GetFullPathName(".", 0, buffer, NULL);
buffer = new char[buflen + 1];
buflen = GetFullPathName(".", buflen + 1, buffer, NULL);
Unicode::String srcPath = Unicode::narrowToWide(buffer);
delete[] buffer;
// get the destination path
std::string correctPath(getDrive() + getPath());
buflen = GetFullPathName(correctPath.c_str(), 0, buffer, NULL);
buffer = new char[buflen + 1];
buflen = GetFullPathName(correctPath.c_str(), buflen + 1, buffer, NULL);
Unicode::String destPath = Unicode::narrowToWide(buffer);
delete[] buffer;
std::vector<Unicode::String> splitDestPath;
splitPath(destPath, splitDestPath,
static_cast<Unicode::unicode_char_t>(WIN32_PATH_SEPARATOR));
Unicode::String prefix = L"\\\\?\\";
destPath = prefix + splitDestPath[0];
for (size_t i = 1; i < splitDestPath.size(); ++i)
{
destPath += WIN32_PATH_SEPARATOR;
destPath += splitDestPath[i];
if (SetCurrentDirectoryW(destPath.c_str()) == 0)
{
if (CreateDirectoryW(destPath.c_str(), NULL) == 0)
return;
if (SetCurrentDirectoryW(destPath.c_str()) == 0)
return;
}
}
// set the directory back to the working directory
SetCurrentDirectoryW(srcPath.c_str());
}
else
{
char *buffer = NULL;
DWORD buflen;
// get our current path
buflen = GetFullPathName(".", 0, buffer, NULL);
buffer = new char[buflen + 1];
buflen = GetFullPathName(".", buflen + 1, buffer, NULL);
std::string srcPath = buffer;
delete[] buffer;
// get the destination path
std::string correctPath(getDrive() + getPath());
buflen = GetFullPathName(correctPath.c_str(), 0, buffer, NULL);
buffer = new char[buflen + 1];
buflen = GetFullPathName(correctPath.c_str(), buflen + 1, buffer, NULL);
std::string destPath = buffer;
delete[] buffer;
// change to the destination path
if (destPath.size() >= MAX_PATH)
return;
std::vector<std::string> splitDestPath;
splitPath(destPath, splitDestPath, WIN32_PATH_SEPARATOR);
destPath = splitDestPath[0];
for (size_t i = 1; i < splitDestPath.size(); ++i)
{
destPath += WIN32_PATH_SEPARATOR;
destPath += splitDestPath[i];
if (SetCurrentDirectory(destPath.c_str()) == 0)
{
if (CreateDirectory(destPath.c_str(), NULL) == 0)
return;
if (SetCurrentDirectory(destPath.c_str()) == 0)
return;
}
}
// set the directory back to the working directory
SetCurrentDirectory(srcPath.c_str());
}
#elif defined(linux)
// @todo: implement for linux
#endif
} // Filename::verifyAndCreatePath
@@ -0,0 +1,121 @@
//========================================================================
//
// Filename.h - a fully qualified file name
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_Filename_H
#define _INCLUDED_Filename_H
class Filename
{
public:
Filename(void);
Filename(const char *drive, const char *path, const char *name, const char *extension);
operator const char *(void) const;
void clear(void);
const std::string & getPath(void) const;
const std::string & getName(void) const;
const std::string & getExtension(void) const;
const std::string & getFullFilename(void) const;
const std::string getAbsolutePath(void) const;
void setPath(const char *path);
void setName(const char *name);
void setExtension(const char *extension);
void prependPath(const Filename &path);
void appendPath(const Filename &path);
void normalizePath(void);
void verifyAndCreatePath(void) const;
const std::string & getDrive(void) const;
void setDrive(const char *drive);
private:
void convertToSystemPath(std::string & path);
void makeFullPath(void);
std::string m_path; // path (not including drive in windows)
std::string m_name; // file name sans path & extension
std::string m_extension; // file extension (plus '.')
std::string m_fullFilename; // fully qualified filename
std::string m_drive; // drive letter (plus ':')
};
inline Filename::Filename(void)
{
} // Filename::Filename
inline Filename::Filename(const char *drive, const char *path, const char *name, const char *extension)
{
if (drive != NULL)
setDrive(drive);
if (path != NULL)
setPath(path);
if (name != NULL)
setName(name);
if (extension != NULL)
setExtension(extension);
} // Filename::Filename
inline Filename::operator const char *(void) const
{
return m_fullFilename.c_str();
} // Filename::operator const char *
inline void Filename::clear(void)
{
m_path = "";
m_name = "";
m_extension = "";
m_fullFilename = "";
m_drive = "";
} // Filename::clear
inline const std::string & Filename::getPath(void) const
{
return m_path;
} // Filename::getPath
inline const std::string & Filename::getName(void) const
{
return m_name;
} // Filename::getName
inline const std::string & Filename::getExtension(void) const
{
return m_extension;
} // Filename::getExtension
inline const std::string & Filename::getFullFilename(void) const
{
return m_fullFilename;
} // Filename::getFullFilename
inline const std::string & Filename::getDrive(void) const
{
return m_drive;
} // Filename::getDrive
inline void Filename::makeFullPath(void)
{
normalizePath();
m_fullFilename = m_drive + m_path + m_name + m_extension;
} // Filename::makeFullPath
//========================================================================
const Filename NEXT_HIGHER_PATH(NULL, "..", NULL, NULL);
#endif // _INCLUDED_Filename_H
@@ -0,0 +1,10 @@
#include "sharedFoundationTypes/FoundationTypes.h"
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <list>
@@ -0,0 +1,86 @@
// ======================================================================
//
// ObjectTemplate.cpp - This is a scaled-down version of ObjectTemplate from
// sharedObject library in order to avoid nasty dependencies.
//
// jeff grills
//
// copyright 1999 Bootprint Entertainment
//
// ======================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "ObjectTemplate.h"
#include "sharedFile/Iff.h"
//-----------------------------------------------------------------
template <> ObjectTemplateList::CreateDataResourceMap *ObjectTemplateList::ms_bindings = NULL;
template <> ObjectTemplateList::LoadedDataResourceMap *ObjectTemplateList::ms_loaded = NULL;
// ======================================================================
/**
* Construct an ObjectTemplate.
*
* @param newName name of the ObjectTemplate
*
*/
ObjectTemplate::ObjectTemplate(const std::string & filename) :
DataResource(filename.c_str()),
m_baseData(0)
{
} // ObjectTemplate::ObjectTemplate
// ----------------------------------------------------------------------
/**
* Destroy an ObjectTemplate.
*/
ObjectTemplate::~ObjectTemplate(void)
{
if (m_baseData != NULL)
{
m_baseData->releaseReference();
m_baseData = NULL;
}
}
// ----------------------------------------------------------------------
void ObjectTemplate::load(Iff &iff)
{
UNREF (iff);
DEBUG_FATAL (true, ("this function should not be called"));
}
// ----------------------------------------------------------------------
/**
* Adds a reference on this template and also adds a reference on the
* template's base.
*/
void ObjectTemplate::addReference(void) const
{
if (m_baseData != NULL)
m_baseData->addReference();
DataResource::addReference();
} // ObjectTemplate::addReference
// ----------------------------------------------------------------------
/**
* Releases a reference on this template and also releases a reference on the
* template's base.
*/
void ObjectTemplate::releaseReference(void) const
{
if (m_baseData != NULL)
m_baseData->releaseReference();
DataResource::releaseReference();
} // ObjectTemplate::releaseReference
// ======================================================================
@@ -0,0 +1,132 @@
// ======================================================================
//
// ObjectTemplate.h - This is a scaled-down version of ObjectTemplate from
// sharedObject library in order to avoid nasty dependencies.
//
// jeff grills
//
// copyright 1999 Bootprint Entertainment
//
// ======================================================================
#ifndef _INCLUDED_ObjectTemplate_H
#define _INCLUDED_ObjectTemplate_H
// ======================================================================
class ObjectTemplate;
#include "sharedFile/Iff.h"
#include "sharedFoundation/CrcLowerString.h"
#include "sharedFoundation/DataResource.h"
#include "sharedFoundation/DataResourceList.h"
typedef DataResourceList<ObjectTemplate> ObjectTemplateList;
// ======================================================================
// Base class for ObjectTemplates
class ObjectTemplate : public DataResource
{
public:
explicit ObjectTemplate(const std::string & filename);
virtual ~ObjectTemplate(void) = 0;
void loadFromIff(Iff &file);
void saveToIff(Iff &file);
virtual Tag getId(void) const = 0;
virtual void addReference(void) const;
virtual void releaseReference(void) const;
protected:
virtual void release(void) const;
virtual void preLoad(void);
virtual void load(Iff &file) = 0;
virtual void postLoad(void);
virtual void preSave(void);
virtual void save(Iff &file) = 0;
virtual void postSave(void);
// static void registerTemplate(Tag id,
// ObjectTemplateList::CreateDataResourceFunc createFunc);
protected:
const ObjectTemplate *m_baseData; // template to use as a base for this template
private:
ObjectTemplate(const ObjectTemplate &);
ObjectTemplate &operator =(const ObjectTemplate &);
};
// ======================================================================
inline void ObjectTemplate::release(void) const
{
ObjectTemplateList::release(*this);
} // ObjectTemplate::release
inline void ObjectTemplate::loadFromIff(Iff &file)
{
preLoad();
load(file);
postLoad();
} // ObjectTemplate::loadFromIff
/**
* Function called before the template is loaded.
*/
inline void ObjectTemplate::preLoad(void)
{
} // ObjectTemplate::preLoad
/**
* Function called after the template is loaded.
*/
inline void ObjectTemplate::postLoad(void)
{
} // ObjectTemplate::postLoad
inline void ObjectTemplate::saveToIff(Iff &file)
{
preSave();
save(file);
postSave();
} // ObjectTemplate::saveToIff
/**
* Function called before the template is saved.
*/
inline void ObjectTemplate::preSave(void)
{
} // ObjectTemplate::preSave
/**
* Saves the template data to an iff file.
*
* @param file file to save to
*/
inline void ObjectTemplate::save(Iff &file)
{
UNREF(file);
} // ObjectTemplate::save
/**
* Function called after the template is saved.
*/
inline void ObjectTemplate::postSave(void)
{
} // ObjectTemplate::postSave
#endif // _INCLUDED_ObjectTemplate_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,247 @@
//========================================================================
//
// TemplateData.h - data for a given version of a template
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_TemplateData_H
#define _INCLUDED_TemplateData_H
#include "sharedFoundation/Tag.h"
#include "TemplateGlobals.h"
class File;
class TemplateDefinitionFile;
class TpfTemplate;
class TemplateDataIterator;
static const int INVALID_ENUM_RESULT = INT_MIN;
struct TagInfo
{
Tag tag;
std::string tagString;
};
class TemplateData
{
friend class TemplateDataIterator;
public:
// public enums
enum ParamType
{
TYPE_NONE,
TYPE_COMMENT,
TYPE_INTEGER,
TYPE_FLOAT,
TYPE_BOOL,
TYPE_STRING,
TYPE_STRINGID,
TYPE_VECTOR,
TYPE_DYNAMIC_VAR,
TYPE_TEMPLATE,
TYPE_ENUM,
TYPE_STRUCT,
TYPE_TRIGGER_VOLUME,
TYPE_FILENAME,
NUM_PARAM_TYPES
};
enum ListType
{
LIST_NONE,
LIST_LIST,
LIST_INT_ARRAY,
LIST_ENUM_ARRAY
};
// info about a template parameter
struct Parameter
{
ParamType type;
std::string name;
std::string description; // description of the parameter or a line comment
std::string extendedName; // name for template, enum, or struct types
int min_int_limit; // for type range
int max_int_limit; // for type range
float min_float_limit; // for type range
float max_float_limit; // for type range
ListType list_type;
int list_size;
std::string enum_list_name; // enum used for enum indexed list
};
struct EnumData
{
std::string name;
std::string valueName;
int value;
std::string comment;
};
typedef std::vector<EnumData> EnumList;
typedef std::map<std::string, EnumList> EnumMap;
public:
explicit TemplateData(int version, const TemplateDefinitionFile &parent);
explicit TemplateData(const TemplateData *parent, const std::string name);
~TemplateData();
const std::string getName(void) const;
const std::string getBaseName(void) const;
TemplateLocation getTemplateLocation(void) const;
const TagInfo & getVersion(void) const;
bool hasList(void) const;
void setWriteForCompiler(bool flag);
bool isWritingForCompiler(void) const;
// template definition parsing functions
const char * parseLine(const File &fp, const char *buffer, char *tokenbuf);
const Parameter *getParameter(const char *name, bool deepCheck = false) const;
int parseIntValue(const File &fp, const char * line, const char ** endLine, char * intbuf) const;
int getEnumValue(const char * enumValue) const;
int getEnumValue(const std::string & enumType, const char * enumValue) const;
const EnumList * getEnumList(const std::string & name, bool define) const;
const TemplateData * getStruct(const char *name) const;
const TemplateDefinitionFile * getTdf() const;
const TemplateDefinitionFile * getTdfParent() const;
const TemplateDefinitionFile * getTdfForParameter(const char *parameterName) const;
// template verification functions
bool verifyTemplate(const TpfTemplate *tpfTemplate, const File &file) const;
void updateTemplate(const TpfTemplate *tpfTemplate, File & file) const;
// template C++ writing functions
void writeRegisterTemplate(File &fp, const char * leadInChars) const;
void writeHeaderFwdDecls(File &fp) const;
void writeHeaderParams(File &fp) const;
void writeSourceTemplateIncludes(File &fp) const;
void writeSourceLoadedFlagInit(File &fp) const;
int writeSourceMethods(File &fp) const;
void writeSourceCleanup(File &fp) const;
// template writing functions
void writeDefaultTemplateFile(File &fp) const;
private:
enum ParseState
{
STATE_PARAM,
STATE_ENUM,
STATE_STRUCT
};
typedef std::vector<Parameter> ParameterList;
typedef std::map<std::string, Parameter> ParameterMap;
typedef std::vector<TemplateData *> StructList;
typedef std::map<std::string, TemplateData *> StructMap;
const TemplateDefinitionFile * m_fileParent; // if the data is for the root template
const TemplateData * m_templateParent; // if the data is for a structure in a template
TagInfo m_structId; // id of the structure
bool m_hasTemplateParam; // flag that one of the parameters is a template (for structures)
bool m_hasDynamicVarParam; // flag that one of the parameters is a dynamic variable (for structures)
bool m_hasList; // flag that one of the parameters is a list
std::string m_name; // template name
std::string m_baseName; // name of base class (if any)
bool m_writeForCompilerFlag; // flag that the C++ we are writing is for the template compiler
TagInfo m_version; // version of this data
int m_bracketCount; // number of '[' we haved parsed
ParseState m_parseState; // whether we are parsing parameters, enum def, of struct def
ParameterList m_parameters; // parameters for the template
ParameterMap m_parameterMap; // param name->parameter lookup
EnumList * m_currentEnumList; // current enum being parsed from tdf file
EnumMap m_enumMap; // enums defined for the template
TemplateData * m_currentStruct; // current struct being parsed from tdf file
StructMap m_structMap; // structs defined for the template
StructList m_structList; // structs defined for the template, in order that they were in the definition file
private:
// no default constructor
TemplateData(void);
TemplateData(const TemplateData &parent);
TemplateData & operator =(const TemplateData &);
// access functions
void getTemplateNames(stdset<std::string>::fwd &names) const;
const TemplateDefinitionFile * getFileParent(void) const;
// template definition parsing functions
const char * parseEnum(const File &fp, const char *buffer, char *tokenbuf);
const char * parseStruct(const File &fp, const char *buffer, char *tokenbuf);
// template C++ writing functions
void writeMethodParams(File &fp, const Parameter &param, bool headerParams) const;
void writeHeaderEnums(File &fp) const;
void writeHeaderStructs(File &fp) const;
void writeHeaderMethods(File &fp) const;
void writeHeaderVariables(File &fp) const;
void writeHeaderVariables(File &fp, const ParameterList &list,
const char *namePrefix) const;
void writeStructDefinition(File &fp) const;
void writeSourceStructStart(File &fp) const;
void writeSourceStructStart(File &fp, const std::string &name) const;
void writeSourceReturnBaseValue(File &fp, const Parameter &param, const std::string & minMaxString) const;
int writeSourceGetData(File &fp) const;
void writeSourceTestData(File &fp) const;
void writeSourceGetGeneric(File &fp, const Parameter &param) const;
void writeSourceGetVector(File &fp, const Parameter &param) const;
void writeSourceGetDynamicVariable(File &fp, const Parameter &param) const;
void writeSourceGetTemplate(File &fp, const Parameter &param) const;
void writeSourceGetEnum(File &fp, const Parameter &param) const;
int writeSourceGetStruct(File &fp, const Parameter &param) const;
void writeSourceGetStructAssignments(File &fp, const std::string & versionString, const std::string & minMaxString) const;
void writeSourceReadIff(File &fp) const;
void writeSourceWriteIff(File &fp) const;
// template C++ template compiler functions
void writeCompilerHeaderParams(File &fp) const;
void writeCompilerSourceMethods(File &fp) const;
void writeCompilerHeaderMethods(File &fp) const;
void writeCompilerSourceAccessMethods(File &fp) const;
// default template writing functions
void writeEnumsToDefaultTemplate(File &fp) const;
void writeStructsToDefaultTemplate(File &fp) const;
void writeParamTypeToDefaultTemplate(File &fp, const Parameter &param) const;
void writeParameterDefault(File &fp, const Parameter &param, int index = -1) const;
void writeStructParameterDefault(File &fp, const Parameter &param, bool final) const;
void writeDefaultValue(File &fp, const Parameter &param) const;
};
inline const TagInfo & TemplateData::getVersion(void) const
{
return m_version;
}
inline bool TemplateData::hasList(void) const
{
return m_hasList;
}
inline bool TemplateData::isWritingForCompiler(void) const
{
return m_writeForCompilerFlag;
}
inline const TemplateDefinitionFile * TemplateData::getFileParent(void) const
{
if (m_fileParent != NULL)
return m_fileParent;
if (m_templateParent != NULL)
return m_templateParent->getFileParent();
return NULL;
} // TemplateData::getFileParent
#endif // _INCLUDED_TemplateData_H
@@ -0,0 +1,176 @@
//========================================================================
//
// TemplateDataIterator.cpp
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
// Includes
/////////////////////////////////////
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "TemplateDataIterator.h"
#include "File.h"
#include "TemplateDefinitionFile.h"
// ============================================================================
//
// TemplateDataIterator class methods
//
// ============================================================================
//-----------------------------------------------------------------------------
TemplateDataIterator::TemplateDataIterator()
: m_templateDataToIterate(NULL),
m_numItems(0),
m_noMoreData(true)
{
}
//-----------------------------------------------------------------------------
TemplateDataIterator::TemplateDataIterator(const TemplateData& templateData)
: m_templateDataToIterate(NULL),
m_numItems(0),
m_noMoreData(true)
{
setTo(templateData);
}
//-----------------------------------------------------------------------------
TemplateDataIterator::~TemplateDataIterator()
{
m_templateDataToIterate = NULL;
}
//-----------------------------------------------------------------------------
void
TemplateDataIterator::setTo(const TemplateData &templateData)
{
m_listOfParamLists.clear();
m_templateDataToIterate = &templateData;
// Loop through the TDF and all of its parents and add all of their
// .. parameter lists into this iterator's list collection. When we're
// .. done, the order of parameter lists will start with the base TDF's and
// .. end at the child TDF's.
const ParameterList* parameterListToAdd;
while(m_templateDataToIterate != NULL)
{
parameterListToAdd = &(m_templateDataToIterate->m_parameters);
m_numItems += parameterListToAdd->size();
// Occasionally, TDF files are stubbed and have no parameters. Be sure
// .. not to add them as they just waste our time.
if(!parameterListToAdd->empty())
{
m_listOfParamLists.push_back(parameterListToAdd);
}
// Get the template data from the parent TDF
if(m_templateDataToIterate->m_fileParent != NULL)
{
const TemplateDefinitionFile* parentFile =
m_templateDataToIterate->m_fileParent->getBaseDefinitionFile();
if(parentFile != NULL)
{
m_templateDataToIterate = parentFile->getTemplateData(parentFile->getHighestVersion());
}
else
{
m_templateDataToIterate = NULL;
}
}
else
{
m_templateDataToIterate = NULL;
}
}
// Initialize internal iterators
reset();
}
//-----------------------------------------------------------------------------
bool
TemplateDataIterator::end() const
{
return (m_noMoreData == true);
}
//-----------------------------------------------------------------------------
void
TemplateDataIterator::next()
{
// Increment to the next parameter
++m_currentParamPtr;
// Have we gone to the end of our current parameter list?
if(m_currentParamPtr == (*m_currentParamListPtr)->end())
{
// Go to the next list. If there are no more lists, then
// .. we are done iterating. Otherwise, set the current
// .. parameter to the beginning of the next list.
++m_currentParamListPtr;
if(m_currentParamListPtr == m_listOfParamLists.end())
{
m_noMoreData = true;
}
else
{
m_currentParamPtr = (*m_currentParamListPtr)->begin();
}
}
}
//-----------------------------------------------------------------------------
int
TemplateDataIterator::size() const
{
return m_numItems;
}
//-----------------------------------------------------------------------------
void
TemplateDataIterator::reset()
{
if(m_numItems > 0)
{
m_noMoreData = false;
}
m_currentParamListPtr = m_listOfParamLists.begin();
m_currentParamPtr = (*m_currentParamListPtr)->begin();
}
//-----------------------------------------------------------------------------
const TemplateData::Parameter *
TemplateDataIterator::operator *() const
{
if(this->end())
{
return NULL;
}
else
{
const TemplateData::Parameter *currParam = &(*m_currentParamPtr);
return currParam;
}
}
@@ -0,0 +1,79 @@
// ============================================================================
//
// TemplateDataIterator.h
//
// This class iterates over a TdfFile and provides incremental access to the
// template data contained within. An iterator is provided because TDF's
// inherit most of their parameters, but this detail should be transparent
// to the programmer. Once you want to create a template from a TDF, you don't
// care where the fields come from -- you just want to know what's available.
//
// Initialize a TemplateDataIterator to a TemplateData. Iterating on it will
// provide access to a TemplateData Parameter.
//
// See also TemplateData, Parameter
//
// Used by TemplateEditor
//
// Copyright Sony Online Entertainment
//
// ============================================================================
#ifndef TEMPLATEDATAITERATOR_H
#define TEMPLATEDATAITERATOR_H
#include "TemplateData.h"
class TemplateDataIterator
{
public:
// Public typedefs and enumerations
/////////////
typedef TemplateData::Parameter Parameter;
// Construction / destruction
/////////////
TemplateDataIterator();
explicit TemplateDataIterator(const TemplateData &templateData);
~TemplateDataIterator();
// Iteration
/////////////
void setTo(const TemplateData &templateData);
bool end() const;
void next();
void reset();
// Accessors
/////////////
int size() const;
const Parameter* operator *() const;
private:
// Private typedefs and enumerations
/////////////
// Template data's store their parameters in parameter lists
typedef TemplateData::ParameterList ParameterList;
typedef ParameterList::const_iterator ParameterListItr;
// Our parameter iterator needs to iterate over lists of parameter lists
typedef std::list<const ParameterList *> ParameterListList;
typedef ParameterListList::const_iterator ParameterListListItr;
// Private Data
/////////////
const TemplateData *m_templateDataToIterate;
ParameterListList m_listOfParamLists; // A list of param lists, one from each TDF ancestor.
ParameterListListItr m_currentParamListPtr; // Current param list we are iterating through
ParameterListItr m_currentParamPtr; // Current parameter we are iterating on
int m_numItems;
bool m_noMoreData;
};
#endif // TEMPLATEDATAITERATOR_H
@@ -0,0 +1,631 @@
//========================================================================
//
// TemplateDefinitionFile.cpp - a template definition file interpreter.
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "File.h"
#include "TemplateGlobals.h"
#include "TemplateDefinitionFile.h"
#include "TemplateData.h"
#include "sharedRegex/RegexServices.h"
#include "sharedFoundation/SetupSharedFoundation.h"
//==============================================================================
/**
* Class constructor.
*/
TemplateDefinitionFile::TemplateDefinitionFile(void) :
m_baseDefinitionFile(NULL),
m_writeForCompilerFlag(false),
m_filterCompiledRegex(NULL)
{
cleanup();
} // TemplateDefinitionFile::TemplateDefinitionFile
/**
* Class destructor.
*/
TemplateDefinitionFile::~TemplateDefinitionFile()
{
cleanup();
} // TemplateDefinitionFile::~TemplateDefinitionFile
/**
* Resets all the class data.
*/
void TemplateDefinitionFile::cleanup(void)
{
m_highestVersion = 0;
m_templateId.tag = NO_TAG;
m_templateId.tagString = NO_TAG_STRING;
m_templateLocation = LOC_NONE;
IGNORE_RETURN(m_templateName.erase());
IGNORE_RETURN(m_baseName.erase());
IGNORE_RETURN(m_templateNameFilter.erase());
m_path.clear();
m_compilerPath.clear();
m_fileComments.clear();
if (m_baseDefinitionFile != NULL)
{
delete m_baseDefinitionFile;
m_baseDefinitionFile = NULL;
}
std::map<int, TemplateData *>::iterator iter;
for (iter = m_templateMap.begin(); iter != m_templateMap.end(); ++iter)
{
delete (*iter).second;
(*iter).second = NULL;
}
m_templateMap.clear();
if (m_filterCompiledRegex != NULL)
{
RegexServices::freeMemory(m_filterCompiledRegex);
m_filterCompiledRegex = NULL;
}
} // TemplateDefinitionFile::cleanup
/**
* Sets the write for compile flags on the tamplate data instances.
*
* @param flag flag that we are going to write code for the template compiler
*/
void TemplateDefinitionFile::setWriteForCompiler(bool flag)
{
m_writeForCompilerFlag = flag;
if (flag && m_baseName.size() == 0)
{
m_baseName = COMPILER_ROOT_TEMPLATE_NAME;
}
else if (!flag && m_baseName == COMPILER_ROOT_TEMPLATE_NAME)
{
m_baseName = "";
}
std::map<int, TemplateData *>::iterator iter;
for (iter = m_templateMap.begin(); iter != m_templateMap.end(); ++iter)
(*iter).second->setWriteForCompiler(flag);
} // TemplateDefinitionFile::setWriteForCompiler
/**
* Returns the template file name filter for this definition.
*/
const std::string & TemplateDefinitionFile::getTemplateNameFilter(void) const
{
static const std::string wildcard = "*";
if (!m_templateNameFilter.empty())
return m_templateNameFilter;
if (m_baseDefinitionFile != NULL)
return m_baseDefinitionFile->getTemplateNameFilter();
return wildcard;
} // TemplateDefinitionFile::getTemplateNameFileter
/**
* Tests if a template file name is valid for this definition.
*
* @param name the template file name
*
* @return true if the name is valid, false if not
*/
bool TemplateDefinitionFile::isValidTemplateName(const Filename & name) const
{
if (m_templateNameFilter.empty())
{
if (m_baseDefinitionFile != NULL)
return m_baseDefinitionFile->isValidTemplateName(name);
else
return true;
}
int const maxCaptureCount = 10;
int const matchDataElementCount = maxCaptureCount * 3;
int matchData[matchDataElementCount];
int const matchCode = pcre_exec(m_filterCompiledRegex, NULL, name.getName().c_str(), name.getName().length(), 0, 0, matchData, matchDataElementCount);
bool const result = (matchCode >= 0);
if (matchCode < -1)
{
fprintf(stderr, "ERROR: pcre_exec() failed, error code [%d].\n", matchCode);
return false;
}
return result;
} // TemplateDefinitionFile::isValidTemplateName
/**
* Writes file-level comments.
*
* @param fp the file to write to
*/
void TemplateDefinitionFile::writeFileComments(File &fp) const
{
std::vector<std::string>::const_iterator iter;
for (iter = getFileComments().begin(); iter != getFileComments().end(); ++iter)
{
fp.print("%s\n", (*iter).c_str());
}
} // TemplateDefinitionFile::writeFileComments
/**
* Writes the template id tag definition.
*
* @param fp the file to write to
*/
void TemplateDefinitionFile::writeTemplateId(File &fp) const
{
fp.print("%s\n", TDF_ID_BEGIN);
fp.print("\tenum\n");
fp.print("\t{\n");
fp.print("\t\t%s_tag = %s\n", getTemplateName().c_str(), getTemplateId().tagString.c_str());
fp.print("\t};\n");
fp.print("%s\n", TDF_ID_END);
} // TemplateDefinitionFile::writeTemplateId
/**
* Writes the beginning of a class header file.
*
* @param fp the file to write to
*/
void TemplateDefinitionFile::writeClassHeaderBegin(File &fp) const
{
const char * name = getTemplateName().c_str();
const char * baseName = getBaseName().c_str();
const char * baseNamePath = "";
if (baseName[0] == '\0' && m_templateLocation != LOC_NONE)
{
baseNamePath = "sharedObject/";
baseName = ROOT_TEMPLATE_NAME;
}
else if(_stricmp(baseName, "tpfTemplate") == 0)
{
baseNamePath = "sharedTemplateDefinition/";
}
fp.print("//========================================================================\n");
fp.print("//\n");
fp.print("// %s.h\n", name);
fp.print("//\n");
fp.print("//IMPORTANT: Any code between //@BEGIN TFD... and //@END TFD... will be\n");
fp.print("//overwritten the next time the template definition is compiled. Do not\n");
fp.print("//make changes to code inside these blocks.\n");
fp.print("//\n");
if (getFileComments().size() > 0)
{
writeFileComments(fp);
fp.print("//\n");
}
fp.print("// copyright 2001 Sony Online Entertainment\n");
fp.print("//\n");
fp.print("//========================================================================\n");
fp.print("\n");
fp.print("#ifndef _INCLUDED_%s_H\n", name);
fp.print("#define _INCLUDED_%s_H\n", name);
fp.print("\n");
fp.print("#include \"%s%s.h\"\n", baseNamePath, baseName);
fp.print("#include \"sharedFoundation/DynamicVariable.h\"\n");
if (m_writeForCompilerFlag)
fp.print("#include \"sharedTemplateDefinition/TpfTemplate.h\"\n");
else
fp.print("#include \"sharedUtility/TemplateParameter.h\"\n");
fp.print("\n");
fp.print("\n");
fp.print("class Vector;\n");
fp.print("typedef StructParam<ObjectTemplate> StructParamOT;\n");
if (!m_writeForCompilerFlag)
{
std::map<int, TemplateData *>::const_iterator iter;
iter = m_templateMap.find(m_highestVersion);
if (iter != m_templateMap.end())
(*iter).second->writeHeaderFwdDecls(fp);
}
fp.print("\n");
fp.print("\n");
fp.print("class %s : public %s\n", name, baseName);
fp.print("{\n");
fp.print("public:\n");
writeTemplateId(fp);
fp.print("public:\n");
fp.print("\t %s(const std::string & filename);\n", name);
fp.print("\tvirtual ~%s();\n", name);
fp.print("\n");
fp.print("\tvirtual Tag getId(void) const;\n");
fp.print("\tvirtual Tag getTemplateVersion(void) const;\n");
fp.print("\tvirtual Tag getHighestTemplateVersion(void) const;\n");
if (m_writeForCompilerFlag)
fp.print("\tstatic void install(void);\n");
else
fp.print("\tstatic void install(bool allowDefaultTemplateParams = true);\n");
fp.print("\n");
} // writeClassHeaderBegin
/**
* Writes the ending of a class header file.
*
* @param fp the file to write to
* @param sourceTemplate the template we are writing code for
*/
void TemplateDefinitionFile::writeClassHeaderEnd(File &fp, const TemplateData & sourceTemplate) const
{
UNREF(sourceTemplate);
const char *name = getTemplateName().c_str();
fp.print("\n");
fp.print("private:\n");
fp.print("\tTag m_templateVersion;\t// the template version\n");
fp.print("\tbool m_versionOk;\t// flag that the template version loaded is "
"the one we expect\n");
if (!m_writeForCompilerFlag)
fp.print("\tstatic bool ms_allowDefaultTemplateParams;\t// flag to allow defaut params instead of fataling\n");
fp.print("\n");
fp.print("\tstatic void registerMe(void);\n");
fp.print("\tstatic ObjectTemplate * create(const std::string & filename);\n");
fp.print("\n");
fp.print("\t// no copying\n");
fp.print("\t%s(const %s &);\n", name, name);
fp.print("\t%s & operator =(const %s &);\n", name, name);
fp.print("};\n");
fp.print("\n");
fp.print("\n");
if (m_writeForCompilerFlag)
{
fp.print("inline void %s::install(void)\n", name);
fp.print("{\n");
}
else
{
fp.print("inline void %s::install(bool allowDefaultTemplateParams)\n", name);
fp.print("{\n");
fp.print("\tms_allowDefaultTemplateParams = allowDefaultTemplateParams;\n");
}
sourceTemplate.writeRegisterTemplate(fp, "\t");
fp.print("}\n");
fp.print("\n");
fp.print("\n");
fp.print("#endif\t// _INCLUDED_%s_H\n", name);
} // TemplateDefinitionFile::writeClassHeaderEnd
/**
* Writes the beginning of a class source file.
*
* @param fp the file to write to
* @param sourceTemplate the template we are writing code for
*/
void TemplateDefinitionFile::writeClassSourceBegin(File &fp, const TemplateData & sourceTemplate) const
{
const char *name = getTemplateName().c_str();
fp.print("//========================================================================\n");
fp.print("//\n");
fp.print("// %s.cpp\n", name);
fp.print("//\n");
fp.print("//IMPORTANT: Any code between //@BEGIN TFD... and //@END TFD... will be\n");
fp.print("//overwritten the next time the template definition is compiled. Do not\n");
fp.print("//make changes to code inside these blocks.\n");
fp.print("//\n");
if (getFileComments().size() > 0)
{
writeFileComments(fp);
fp.print("//\n");
}
fp.print("// copyright 2001 Sony Online Entertainment\n");
fp.print("//\n");
fp.print("//========================================================================\n");
fp.print("\n");
if (m_writeForCompilerFlag)
{
fp.print("#include \"sharedTemplate/FirstSharedTemplate.h\"\n");
fp.print("#include \"sharedTemplateDefinition/TemplateData.h\"\n");
fp.print("#include \"sharedTemplateDefinition/TemplateGlobals.h\"\n", name);
}
else if (m_templateLocation == LOC_CLIENT)
fp.print("#include \"%s\"\n", CLIENT_TEMPLATE_PRECOMPILED_HEADER_NAME);
else if (m_templateLocation == LOC_SERVER)
fp.print("#include \"%s\"\n", SERVER_TEMPLATE_PRECOMPILED_HEADER_NAME);
else
fp.print("#include \"%s\"\n", SHARED_TEMPLATE_PRECOMPILED_HEADER_NAME);
fp.print("#include \"%s.h\"\n", name);
fp.print("#include \"sharedDebug/DataLint.h\"\n");
fp.print("#include \"sharedFile/Iff.h\"\n");
if (m_writeForCompilerFlag)
fp.print("#include \"sharedTemplateDefinition/ObjectTemplate.h\"\n");
else
{
fp.print("#include \"sharedObject/ObjectTemplate.h\"\n");
fp.print("#include \"sharedObject/ObjectTemplateList.h\"\n");
sourceTemplate.writeSourceTemplateIncludes(fp);
}
fp.print("#include <stdio.h>\n");
fp.print("\n");
if (!m_writeForCompilerFlag)
{
fp.print("const std::string DefaultString(\"\");\n");
fp.print("const StringId DefaultStringId(\"\", 0);\n");
fp.print("const Vector DefaultVector(0,0,0);\n");
fp.print("const TriggerVolumeData DefaultTriggerVolumeData;\n");
fp.print("\n");
fp.print("bool %s::ms_allowDefaultTemplateParams = true;\n", name);
}
fp.print("\n");
fp.print("\n");
fp.print("/**\n");
fp.print(" * Class constructor.\n");
fp.print(" */\n");
fp.print("%s::%s(const std::string & filename)\n", name, name);
// if (sourceTemplate.hasList())
sourceTemplate.writeSourceLoadedFlagInit(fp);
fp.print("{\n");
// fp.print("\tsetId(%s);\n", getTemplateId().tagString.c_str());
fp.print("} // %s::%s\n", name, name);
fp.print("\n");
fp.print("/**\n");
fp.print(" * Class destructor.\n");
fp.print(" */\n");
fp.print("%s::~%s()\n", name, name);
fp.print("{\n");
sourceTemplate.writeSourceCleanup(fp);
fp.print("} // %s::~%s\n", name, name);
fp.print("\n");
fp.print("/**\n");
fp.print(" * Static function used to register this template.\n");
fp.print(" */\n");
fp.print("void %s::registerMe(void)\n", name);
fp.print("{\n");
fp.print("\tObjectTemplateList::registerTemplate(%s_tag, create);\n", name);
fp.print("} // %s::registerMe\n", name);
fp.print("\n");
fp.print("/**\n");
fp.print(" * Creates a %s template.\n", name);
fp.print(" *\n");
fp.print(" * @return a new instance of the template\n");
fp.print(" */\n");
fp.print("ObjectTemplate * %s::create(const std::string & filename)\n", name);
fp.print("{\n");
fp.print("\treturn new %s(filename);\n", name);
fp.print("} // %s::create\n", name);
fp.print("\n");
fp.print("/**\n");
fp.print(" * Returns the template id.\n");
fp.print(" *\n");
fp.print(" * @return the template id\n");
fp.print(" */\n");
fp.print("Tag %s::getId(void) const\n", name);
fp.print("{\n");
fp.print("\treturn %s_tag;\n", name);
fp.print("} // %s::getId\n", name);
fp.print("\n");
fp.print("/**\n");
fp.print(" * Returns this template's version.\n");
fp.print(" *\n");
fp.print(" * @return the version\n");
fp.print(" */\n");
fp.print("Tag %s::getTemplateVersion(void) const\n", name);
fp.print("{\n");
fp.print("\treturn m_templateVersion;\n");
fp.print("} // %s::getTemplateVersion\n", name);
fp.print("\n");
fp.print("/**\n");
fp.print(" * Returns the highest version of this template or it's base templates.\n");
fp.print(" *\n");
fp.print(" * @return the highest version\n");
fp.print(" */\n");
fp.print("Tag %s::getHighestTemplateVersion(void) const\n", name);
fp.print("{\n");
fp.print("\tif (m_baseData == NULL)\n");
fp.print("\t\treturn m_templateVersion;\n");
fp.print("\tconst %s * base = dynamic_cast<const %s *>(m_baseData);\n", name, name);
fp.print("\tif (base == NULL)\n");
fp.print("\t\treturn m_templateVersion;\n");
fp.print("\treturn std::max(m_templateVersion, base->getHighestTemplateVersion());\n");
fp.print("} // %s::getHighestTemplateVersion\n", name);
fp.print("\n");
} // TemplateDefinitionFile::writeClassSourceBegin
/**
* Main parser for a tdf file. Parses initialization data, creates the header and
* source files, and passes parameter definitions to the appropriate function.
*
* @param fp file to parse
*
* @return 0 on success, -1 on fail
*/
int TemplateDefinitionFile::parse(File &fp)
{
static const int BUFFER_SIZE = 1024;
int lineLen;
char buffer[BUFFER_SIZE];
char token[BUFFER_SIZE];
TemplateData *currentTemplate = NULL;
cleanup();
setTemplateFilename(fp.getFilename().getName());
for (;;)
{
lineLen = fp.readLine(buffer, BUFFER_SIZE);
if (lineLen == -1)
break;
else if (lineLen == -2)
return -1;
const char *line = buffer;
line = getNextWhitespaceToken(line, token);
if (*token == '\0')
break;
if (strcmp(token, "version") == 0)
{
if (m_templateName.size() == 0)
{
fp.printError("no template name defined");
return -1;
}
else if (m_templateId.tag == NO_TAG)
{
fp.printError("no template id defined");
return -1;
}
else if (m_path.getPath().size() == 0)
{
fp.printError("no path defined");
return -1;
}
else if (m_compilerPath.getPath().size() == 0)
{
fp.printError("no compiler path defined");
return -1;
}
// if (m_baseName.size() == 0 && m_templateName != ROOT_TEMPLATE_NAME)
// m_baseName = ROOT_TEMPLATE_NAME;
line = getNextWhitespaceToken(line, token);
int version = atoi(token);
if (version < 0 || version > 9999)
{
fp.printError("version out of range");
return -1;
}
if (m_templateMap.find(version) != m_templateMap.end())
{
fp.printError("version already defined");
return -1;
}
if (version > m_highestVersion)
m_highestVersion = version;
currentTemplate = new TemplateData(version, *this);
m_templateMap[version] = currentTemplate;
}
else if (currentTemplate != NULL)
{
line = currentTemplate->parseLine(fp, buffer, token);
if (line == CHAR_ERROR)
return -1;
}
else if (*token == '/' && *(token + 1) == '/')
{
if (m_baseName.size() == 0 && m_templateId.tag == NO_TAG)
m_fileComments.push_back(buffer);
}
else if (strcmp(token, "base") == 0)
{
if (m_baseName.size() != 0)
{
fp.printError("base name already defined");
return -1;
}
line = getNextWhitespaceToken(line, token);
setBaseFilename(token);
// load and parse the base template
Filename baseFileName = fp.getFilename();
baseFileName.setName(token);
File baseFp(baseFileName, "rt");
if (!baseFp.isOpened())
{
fp.printError("unable to open base template definition");
return -1;
}
if (m_baseDefinitionFile == NULL)
m_baseDefinitionFile = new TemplateDefinitionFile;
else
m_baseDefinitionFile->cleanup();
int result = m_baseDefinitionFile->parse(baseFp);
if (result != 0)
return result;
}
else if (strcmp(token, "id") == 0)
{
if (m_templateId.tag != NO_TAG)
{
fp.printError("template id already defined");
return -1;
}
line = getNextWhitespaceToken(line, token);
if (strlen(token) != 4)
{
fp.printError("id not 4 characters");
return -1;
}
m_templateId.tag = ConvertStringToTag(token);
m_templateId.tagString = ConvertStringToTagString(token);
}
else if (strcmp(token, "templatename") == 0)
{
line = getNextWhitespaceToken(line, token);
m_templateNameFilter = token;
//-- Attempt to compile the regex.
if (m_filterCompiledRegex != NULL)
{
// First free the existing compiled regex.
RegexServices::freeMemory(m_filterCompiledRegex);
m_filterCompiledRegex = NULL;
}
//-- Compile the new regex.
char const *errorString = NULL;
int errorOffset = 0;
m_filterCompiledRegex = pcre_compile(m_templateNameFilter.c_str(), 0, &errorString, &errorOffset, NULL);
WARNING(m_filterCompiledRegex == NULL, ("TemplateDefinitionFile::parse(): pcre_compile() failed, error=[%s], errorOffset=[%d], regex text=[%s].", errorString, errorOffset, m_templateNameFilter.c_str()));
}
else if (strcmp(token, "clientpath") == 0 ||
strcmp(token, "serverpath") == 0 ||
strcmp(token, "sharedpath") == 0)
{
if (m_path.getPath().size() != 0)
{
fp.printError("path already defined");
return -1;
}
if (strcmp(token, "clientpath") == 0)
m_templateLocation = LOC_CLIENT;
else if (strcmp(token, "serverpath") == 0)
m_templateLocation = LOC_SERVER;
else
m_templateLocation = LOC_SHARED;
line = getNextWhitespaceToken(line, token);
m_path.setPath(token);
m_path.prependPath(fp.getFilename());
// reset the template name to add the corrent prefix to the template
// name
setTemplateFilename(m_templateFilename);
if (!m_baseFilename.empty())
setBaseFilename(m_baseFilename);
}
else if (strcmp(token, "compilerpath") == 0)
{
if (m_compilerPath.getPath().size() != 0)
{
fp.printError("compiler path already defined");
return -1;
}
line = getNextWhitespaceToken(line, token);
m_compilerPath.setPath(token);
m_compilerPath.prependPath(fp.getFilename());
}
else
{
char errbuf[2048];
sprintf(errbuf, "I don't know how to handle this line!: <%s>. "
"Barfed on token <%s>.", buffer, token);
fp.printError(errbuf);
return -1;
}
}
return 0;
} // TemplateDefinitionFile::parse
@@ -0,0 +1,159 @@
//========================================================================
//
// TemplateDefinitionFile.h - a template definition file interpreter.
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_TemplateDefinitionFile_H
#define _INCLUDED_TemplateDefinitionFile_H
#include "pcre.h"
#include "sharedFoundation/Tag.h"
#include "TemplateData.h"
class File;
class TemplateDefinitionFile
{
public:
TemplateDefinitionFile(void);
~TemplateDefinitionFile();
void setTemplateFilename(const std::string &name);
void setBaseFilename(const std::string &name);
bool isWriteForCompiler(void) const;
void setWriteForCompiler(bool flag);
const std::string & getTemplateNameFilter(void) const;
bool isValidTemplateName(const Filename & name) const;
void writeFileComments(File &fp) const;
void writeTemplateId(File &fp) const;
void writeClassHeaderBegin(File &fp) const;
void writeClassHeaderEnd(File &fp, const TemplateData & sourceTemplate) const;
void writeClassSourceBegin(File &fp, const TemplateData & sourceTemplate) const;
int parse(File &fp);
const Filename & getPath(void) const;
const Filename & getCompilerPath(void) const;
TemplateLocation getTemplateLocation(void) const;
TemplateData * getTemplateData(int version) const;
const std::vector<std::string> & getFileComments(void) const;
const std::string & getTemplateName(void) const;
const std::string & getTemplateFilename(void) const;
const std::string & getBaseName(void) const;
const std::string & getBaseFilename(void) const;
const TemplateDefinitionFile * getBaseDefinitionFile(void) const;
const TagInfo & getTemplateId(void) const;
int getHighestVersion(void) const;
private:
void cleanup(void);
Filename m_path;
Filename m_compilerPath;
TemplateLocation m_templateLocation;
std::map<int, TemplateData *> m_templateMap;
std::vector<std::string> m_fileComments;
std::string m_templateName;
std::string m_templateFilename;
std::string m_baseName;
std::string m_baseFilename;
TemplateDefinitionFile * m_baseDefinitionFile;
TagInfo m_templateId;
bool m_writeForCompilerFlag; // flag that the C++ we are writing is for the template compiler
int m_highestVersion;
std::string m_templateNameFilter;
pcre *m_filterCompiledRegex;
};
inline void TemplateDefinitionFile::setTemplateFilename(const std::string &name)
{
m_templateFilename = name;
m_templateName = EnumLocationTypes[m_templateLocation] +
filenameLowerToUpper(name);
}
inline void TemplateDefinitionFile::setBaseFilename(const std::string &name)
{
m_baseFilename = name;
m_baseName = EnumLocationTypes[m_templateLocation] +
filenameLowerToUpper(name);
}
inline bool TemplateDefinitionFile::isWriteForCompiler(void) const
{
return m_writeForCompilerFlag;
}
inline const Filename & TemplateDefinitionFile::getPath(void) const
{
return m_path;
}
inline const Filename & TemplateDefinitionFile::getCompilerPath(void) const
{
return m_compilerPath;
}
inline TemplateLocation TemplateDefinitionFile::getTemplateLocation(void) const
{
return m_templateLocation;
}
inline TemplateData *TemplateDefinitionFile::getTemplateData(int version) const
{
std::map<int, TemplateData *>::const_iterator iter = m_templateMap.find(version);
if (iter == m_templateMap.end())
return NULL;
return (*iter).second;
}
inline const std::vector<std::string> &TemplateDefinitionFile::getFileComments(void) const
{
return m_fileComments;
}
inline const std::string &TemplateDefinitionFile::getTemplateName(void) const
{
return m_templateName;
}
inline const std::string &TemplateDefinitionFile::getTemplateFilename(void) const
{
return m_templateFilename;
}
inline const std::string &TemplateDefinitionFile::getBaseName(void) const
{
return m_baseName;
}
inline const std::string &TemplateDefinitionFile::getBaseFilename(void) const
{
return m_baseFilename;
}
inline const TemplateDefinitionFile * TemplateDefinitionFile::getBaseDefinitionFile(void) const
{
return m_baseDefinitionFile;
}
inline const TagInfo & TemplateDefinitionFile::getTemplateId(void) const
{
return m_templateId;
}
inline int TemplateDefinitionFile::getHighestVersion(void) const
{
return m_highestVersion;
}
#endif // _INCLUDED_TemplateDefinitionFile_H
@@ -0,0 +1,312 @@
//========================================================================
//
// TemplateGlobals.cpp - global functions/data
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "TemplateGlobals.h"
#ifdef WIN32
bool WindowsUnicode = false;
#endif
//==============================================================================
// functions
/**
* Strips a character string of leading and trailing whitespace.
*
* @param buffer the string to strip
*
* @return the length of the stripped string
*/
int strip(char *buffer)
{
NOT_NULL(buffer);
// find the 1st non-space character
char *to = buffer;
char *from = buffer;
while (isspace(*from) && *from != '\0')
++from;
if (*from == '\0') // entire line was whitespace
return 0;
// move the string forward
if (from != to)
{
while (*from != '\0')
*to++ = *from++;
*to = '\0';
}
from = buffer + strlen(buffer) - 1;
while (isspace(*from))
--from;
*(from + 1) = '\0';
return from - buffer + 1;
} // strip
/**
* Gets the next whitespace-delimited token from a string.
*
* @param buffer string to get the token from
* @param token buffer to store the token in; assume that it is at least
* the size of buffer
*
* @return the next non-whitespace character in the string after the token, or
* NULL if the end of line has been reached
*/
const char *getNextWhitespaceToken(const char *buffer, char *token)
{
NOT_NULL(token);
*token = '\0';
if (buffer == NULL)
return NULL;
const char *from = buffer;
char *to = token;
// skip any leading whitespace
while (isspace(*from) && *from != '\0')
++from;
if (*from == '\0')
return NULL;
// copy the token
while (!isspace(*from) && *from != '\0')
*to++ = *from++;
*to = '\0';
// skip trailing whitespace
while (isspace(*from) && *from != '\0')
++from;
if (*from == '\0')
return NULL;
return from;
} // getNextWhitespaceToken
/**
* Gets the next token from a string.
*
* @param buffer string to get the token from
* @param token buffer to store the token in; assume that it is at least
* the size of buffer
*
* @return the next token, defined by the 1st non-whitespace character in buffer:
* if it is '/' and the next character is '/', NULL
* if it is a double-quote, the text until the next double quote (not including \")
* if it is a symbol, the symbol
* if it is a number, the next characters that make a valid integer or float
* if it is a character, the text until the next whitespace or symbol, not including _
* if it is NULL, NULL
*/
const char *getNextToken(const char *buffer, char *token)
{
NOT_NULL(token);
*token = '\0';
if (buffer == NULL)
return NULL;
const char *from = buffer;
char *to = token;
// skip any leading whitespace
while (isspace(*from) && *from != '\0')
++from;
if (*from == '\0')
return NULL;
if (*from == '/' && *(from+1) == '/')
{
// comment
return NULL;
}
else if (isdigit(*from) ||
((*from == '+' || *from == '-') && isdigit(*(from + 1)))
)
{
*to++ = *from++;
while (isdigit(*from) && *from != '\0')
*to++ = *from++;
if (*from == '.' && isdigit(*(from + 1)))
{
*to++ = *from++;
while (isdigit(*from) && *from != '\0')
*to++ = *from++;
}
}
else if (isalpha(*from))
{
while ((isalnum(*from) || *from == '_') && *from != '\0')
*to++ = *from++;
}
else if (*from == '"')
{
*to++ = *from++;
while (*from != '"' && *from != '\0')
{
if (*from != '\\')
*to++ = *from++;
else
{
// copy the \ and the next character blindly
*to++ = *from++;
if (*from != '\0')
*to++ = *from++;
}
}
if (*from == '"')
*to++ = *from++;
}
else
{
*to++ = *from++;
}
*to = '\0';
// skip trailing whitespace
while (isspace(*from) && *from != '\0')
++from;
if (*from == '\0')
return NULL;
return from;
} // getNextToken
/**
* Converts a file name in the form name1_name2_name3 to Name1Name2Name3.
*
* @param filename the lower-case file name
*
* @return the file name converted to upper case
*/
std::string filenameLowerToUpper(const std::string & filename)
{
size_t count = filename.size();
std::string newname;
newname.reserve(count);
for (size_t i = 0; i < count; ++i)
{
if (i > 0)
{
if (filename[i] != '_')
newname += filename[i];
else
newname += static_cast<char>(toupper(filename[++i]));
}
else
newname += static_cast<char>(toupper(filename[i]));
}
return newname;
} // filenameLowerToUpper
/**
* Converts a file name in the form Name1Name2Name3 to name1_name2_name3.
*
* @param filename the upper-case file name
*
* @return the file name converted to lower case
*/
std::string filenameUpperToLower(const std::string & filename)
{
size_t count = filename.size();
std::string newname;
newname.reserve(count + 5); // add some padding for underscores
for (size_t i = 0; i < count; ++i)
{
if (i > 0)
{
if (!isupper(filename[i]))
newname += filename[i];
else
{
newname += '_';
newname += static_cast<char>(tolower(filename[i]));
}
}
else
newname += static_cast<char>(tolower(filename[i]));
}
return newname;
} // filenameUpperToLower
/**
* Concatinates two paths together.
*
* @param path1 original path
* @param path2 path to concatinate to path2
*
* @return the concatinated path
*
std::string concatPaths(const char *path1, const char *path2)
{
// test for missing path
if (path1 == NULL || *path1 == '\0')
return path2;
if (path2 == NULL || *path2 == '\0')
return path1;
#ifdef WIN32
// test if path2 is an absolute path
if ((isalpha(*path2) && *(path2 + 1) == ':') || *path2 == PATH_SEPARATOR)
return path2;
#else
if (*path2 == PATH_SEPARATOR)
return path2;
#endif
std::string path = path1;
if (path1[strlen(path1) - 1] != PATH_SEPARATOR)
path += PATH_SEPARATOR;
path += path2;
return path;
} // concatPaths
*/
/**
* Finds the next highest path of a given path.
*
* @param path the original path
*
* @return the new path
*
std::string getNextHighestPath(const char *path)
{
NOT_NULL(path);
// find the two highest path separators
const char *separator1 = strrchr(path, PATH_SEPARATOR);
if (separator1 == NULL)
{
#ifdef WIN32
if (isalpha(*path) && *(path + 1) == ':')
return std::string(path, 2);
else
return std::string();
#else
return std::string();
#endif
}
else if (separator1 == path)
return std::string(path, 1);
#ifdef WIN32
else if (isalpha(*path) && *(path + 1) == ':' && separator1 == path + 2)
return std::string(path, 3);
#endif
const char *separator2 = strrchr(separator1 - 1, PATH_SEPARATOR);
if (separator2 == NULL)
return std::string(path, separator1 - path);
return std::string(path, separator2 - path);
} // getNextHighestPath
*/
@@ -0,0 +1,161 @@
//========================================================================
//
// TemplateGlobals.h - program globals
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_TemplateGlobals_H
#define _INCLUDED_TemplateGlobals_H
#include <string>
#include "sharedFoundation/Tag.h"
//========================================================================
// constants
const int MAX_DIRECTORY_DEPTH = 64; // assume we never have a directory deeper than this
const char * const ROOT_TEMPLATE_NAME = "ObjectTemplate";
const char * const COMPILER_ROOT_TEMPLATE_NAME = "TpfTemplate";
const char * const CLIENT_TEMPLATE_PRECOMPILED_HEADER_NAME = "clientGame/FirstClientGame.h";
const char * const SERVER_TEMPLATE_PRECOMPILED_HEADER_NAME = "serverGame/FirstServerGame.h";
const char * const SHARED_TEMPLATE_PRECOMPILED_HEADER_NAME = "sharedGame/FirstSharedGame.h";
const char * const TDF_BEGIN = "//@BEGIN TFD";
const char * const TDF_END = "//@END TFD";
const char * const TDF_ID_BEGIN = "//@BEGIN TFD ID";
const char * const TDF_ID_END = "//@END TFD ID";
const char * const TDF_TEMPLATE_REFS_BEGIN = "//@BEGIN TFD TEMPLATE REFS";
const char * const TDF_TEMPLATE_REFS_END = "//@END TFD TEMPLATE REFS";
const char * const TDF_INSTALL_BEGIN = "//@BEGIN TFD INSTALL";
const char * const TDF_INSTALL_END = "//@END TFD INSTALL";
const char * const TDF_INIT_BEGIN = "//@BEGIN TFD INIT";
const char * const TDF_INIT_END = "//@END TFD INIT";
const char * const TDF_CLEANUP_BEGIN = "//@BEGIN TFD CLEANUP";
const char * const TDF_CLEANUP_END = "//@END TFD CLEANUP";
const char * const TDF_INLINES_BEGIN = "//@BEGIN TFD INLINES";
const char * const TDF_INLINES_END = "//@END TFD INLINES";
const char * const TEMPLATE_DEFINITION_EXTENSION = "tdf";
const char * const TEMPLATE_EXTENSION = "tpf";
const char * const IFF_EXTENSION = "iff";
const char * const TEMPLATE_BINARY_EXSTENSION = IFF_EXTENSION;
const Tag NO_TAG = TAG(0,0,0,0);
const char * const NO_TAG_STRING = "TAG(0,0,0,0)";
const Tag DERIVED_TEMPLATE_TAG = TAG(D,E,R,V);
const char * const DERIVED_TEMPLATE_TAG_STRING = "TAG(D,E,R,V)";
// this is the error code returned by a function that returns a const char *
const char * const CHAR_ERROR = reinterpret_cast<const char * const>(-1);
enum TemplateLocation
{
LOC_NONE,
LOC_CLIENT,
LOC_SERVER,
LOC_SHARED
};
// map enum TemplateLocation to string types
const char * const EnumLocationTypes[] =
{
"",
"Client",
"Server",
"Shared"
};
//------------------------------------------------------------------------
// global variables
#ifdef WIN32
extern bool WindowsUnicode;
#endif
//------------------------------------------------------------------------
// global functions
extern int strip(char *buffer);
extern const char *getNextWhitespaceToken(const char *buffer, char *token);
extern const char *getNextToken(const char *buffer, char *token);
extern std::string filenameLowerToUpper(const std::string & filename);
extern std::string filenameUpperToLower(const std::string & filename);
//extern std::string concatPaths(const char *path1, const char *path2);
//extern std::string getNextHighestPath(const char *path);
//------------------------------------------------------------------------
// inline functions
inline std::string ConvertStringToTagString(const char *string)
{
static const char SUFFIX[4] = {',', ',', ',', ')'};
std::string tagString = "TAG(";
for (int i = 0; i < 4; ++i)
{
tagString += string[i];
tagString += SUFFIX[i];
}
return tagString;
}
inline bool isinteger(const char *string)
{
char *endptr;
errno = 0;
strtol(string, &endptr, 10);
if (errno == ERANGE || *endptr != '\0')
return false;
return true;
}
inline bool isfloat(const char *string)
{
char *endptr;
strtod(string, &endptr);
if (errno == ERANGE || *endptr != '\0')
{
return false;
}
return true;
}
template<class T>
inline void splitPath(
const std::basic_string<T> & path,
std::vector<std::basic_string<T> > & splitPath,
T splitter
)
{
typename std::basic_string<T>::size_type pos = 0;
typename std::basic_string<T>::size_type oldPos = 0;
for (;;)
{
oldPos = pos;
pos = path.find(splitter, pos);
if (pos != std::basic_string<T>::npos)
{
splitPath.push_back(path.substr(oldPos, pos - oldPos));
++pos;
}
else
{
// splitPath.push_back(path.substr(oldPos, path.size() - oldPos));
return;
}
}
}
//========================================================================
#endif // _INCLUDED_TemplateGlobals_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,224 @@
//========================================================================
//
// TpfFile.h - a template file interpreter.
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_TpfFile_H
#define _INCLUDED_TpfFile_H
#include "File.h"
#include "ObjectTemplate.h"
#include "sharedUtility/TemplateParameter.h"
#include "TemplateDefinitionFile.h"
#include "TemplateData.h"
class CompilerIntegerParam;
class TpfTemplate;
class TpfFile;
typedef StructParam<ObjectTemplate> StructParamOT;
//========================================================================
// friend functions
// can we do this some how?
//template <class T>
//typedef const char * (*ParseParamFuncPtr)(T & param, const char *line);
template <class Q, class LIST, class VALUE>
const char *parseWeightedList(
const char * (*parseFunc)(TpfFile &, Q &, const char *),
TpfFile &file, Q & param, const char *line);
template <class Q>
const char * parseValue(
Q * (*getParamFunc)(TpfTemplate &, const std::string &, int),
const char * (*parseFunc)(TpfFile &, Q &, const char *),
TpfFile &file, const char *line, int arrayIndex);
//========================================================================
//
class TpfFile
{
template <class Q, class LIST, class VALUE>
friend const char *parseWeightedList(
const char * (*parseFunc)(TpfFile &, Q &, const char *),
TpfFile &file, Q & param, const char *line);
template <class Q>
friend const char * parseValue(
Q * (*getParamFunc)(TpfTemplate &, const std::string &, int),
const char * (*parseFunc)(TpfFile &, Q &, const char *),
TpfFile &file, const char *line, int arrayIndex);
public:
TpfFile(void);
~TpfFile();
int loadTemplate(const Filename & filename);
int makeIffFiles(const Filename & filename);
// int updateTemplate(const Filename & filename);
TemplateLocation getTemplateLocation(void) const;
const std::string & getTpfPath(void) const;
const std::string & getPath(void) const;
const std::string & getIffPath(void) const;
std::string getFileName() const;
const std::string & getBaseTemplateName() const;
const TemplateDefinitionFile * getTemplateDefinitionFile() const;
TpfTemplate * getTemplate() const;
public:
enum
{
// we can't define const int values, but we can define enum values
BUFFER_SIZE = 16384
};
File m_fp; // tpf being read
char m_buffer[BUFFER_SIZE]; // storage for reading tpf
char m_token[BUFFER_SIZE]; // storage for next token
TpfTemplate * m_template; // template we are creating
std::string m_baseTemplateName; // temp storage of template we want to derive our template from
TemplateDefinitionFile m_templateDef; // definition file for the template
const TemplateDefinitionFile *m_currTemplateDef; // which definition (in the TDF hierarchy) we're on
const TemplateData * m_templateData; // template data info for the whole TpfFile
const TemplateData * m_highestTemplateData; // template data info for the highest tdf version
const TemplateData::Parameter* m_parameter; // info on current parameter
std::string m_path; // where to put the C++ files
std::string m_iffPath; // where to put the iff files
TemplateLocation m_templateLocation; // what kind of template this is
TemplateData::EnumMap m_enumHeaderMap; // template-wide enum map defined by external c headers
void cleanup(void);
const char * goToNextLine(void);
void printMinIntError(void);
void printMaxIntError(void);
void printMinFloatError(void);
void printMaxFloatError(void);
int WriteIffFile(Iff & iffData, const Filename & fileName);
int parseTemplateCommand(const char *line);
int parseEnumHeader(const char * headerName);
int getEnumHeaderValue(const char * enumValue) const;
const char * parseAssignment(const char *line);
const char * parseIntegerParameter(CompilerIntegerParam & param, const char *line);
const char * parseFloatParameter(FloatParam & param, const char *line);
const char * parseBoolParameter(BoolParam & param, const char *line);
const char * parseStringParameter(StringParam & param, const char *line);
const char * parseStringIdParameter(StringIdParam & param, const char *line);
const char * parseFilenameParameter(StringParam & param, const char *line);
const char * parseVectorParameter(VectorParam & param, const char *line);
const char * parseTemplateParameter(StringParam & param, const char *line);
const char * parseEnumParameter(CompilerIntegerParam & param, const char *line);
const char * parseDynamicVariableParameter(DynamicVariableParam & param, const char *line);
const char * parseDynamicVariableParameterList(DynamicVariableParamData & data, const char *line);
const char * parseStructParameter(StructParamOT & param, const char *line);
const char * parseTriggerVolumeParameter(TriggerVolumeParam & param, const char *line);
private:
// callback functions
static CompilerIntegerParam *getIntegerParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static FloatParam *getFloatParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static BoolParam *getBoolParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static StringParam *getStringParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static StringIdParam *getStringIdParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static VectorParam *getVectorParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static DynamicVariableParam *getDynamicVariableParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static StructParamOT *getStructParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static TriggerVolumeParam *getTriggerVolumeParam2(TpfTemplate &templt,
const std::string &paramName, int arrayIndex);
static const char * parseIntegerParameter2(TpfFile &file,
CompilerIntegerParam & param, const char *line);
static const char * parseFloatParameter2(TpfFile &file,
FloatParam & param, const char *line);
static const char * parseBoolParameter2(TpfFile &file,
BoolParam & param, const char *line);
static const char * parseStringParameter2(TpfFile &file,
StringParam & param, const char *line);
static const char * parseStringIdParameter2(TpfFile &file,
StringIdParam & param, const char *line);
static const char * parseFilenameParameter2(TpfFile &file,
StringParam & param, const char *line);
static const char * parseVectorParameter2(TpfFile &file,
VectorParam & param, const char *line);
static const char * parseTemplateParameter2(TpfFile &file,
StringParam & param, const char *line);
static const char * parseEnumParameter2(TpfFile &file,
CompilerIntegerParam & param, const char *line);
static const char * parseDynamicVariableParameter2(TpfFile &file,
DynamicVariableParam & param, const char *line);
static const char * parseStructParameter2(TpfFile &file,
StructParamOT & param, const char *line);
static const char * parseTriggerVolumeParameter2(TpfFile &file,
TriggerVolumeParam & param, const char *line);
private:
// no copying
TpfFile(const TpfFile &);
TpfFile &operator =(const TpfFile &);
};
inline TemplateLocation TpfFile::getTemplateLocation(void) const
{
return m_templateLocation;
}
inline const std::string & TpfFile::getTpfPath(void) const
{
return m_fp.getFilename().getPath();
}
inline const std::string & TpfFile::getPath(void) const
{
return m_path;
}
inline const std::string & TpfFile::getIffPath(void) const
{
return m_iffPath;
}
inline const TemplateDefinitionFile * TpfFile::getTemplateDefinitionFile() const
{
return &m_templateDef;
}
inline TpfTemplate * TpfFile::getTemplate() const
{
return m_template;
}
//========================================================================
// friend functions
template <class Q, class LIST, class VALUE>
const char *parseWeightedList(
const char * (*parseFunc)(TpfFile &, Q &, const char *),
TpfFile &file, Q & param, const char *line);
template <class Q>
const char * parseValue(
Q * (*getParamFunc)(TpfTemplate &, const std::string &, int),
const char * (*parseFunc)(TpfFile &, Q &, const char *),
TpfFile &file, const char *line, int arrayIndex);
#endif // _INCLUDED_TpfFile_H
@@ -0,0 +1,442 @@
//========================================================================
//
// TpfTemplate.cpp - adds extra functionality to Template for the compiler
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"
#include "sharedTemplateDefinition/TpfTemplate.h"
#include "sharedFile/Iff.h"
#include "sharedTemplateDefinition/TpfFile.h"
//========================================================================
// member functions
/**
* Class constructor.
*/
TpfTemplate::TpfTemplate(const std::string & filename) :
ObjectTemplate(filename),
m_parentFile(NULL),
m_baseTemplateName(),
m_baseTemplateFile(NULL)
{
} // TpfTemplate::TpfTemplate
/**
* Class destructor.
*/
TpfTemplate::~TpfTemplate()
{
m_parentFile = NULL;
m_baseTemplateName.clear();
if (m_baseTemplateFile != NULL)
{
delete m_baseTemplateFile;
m_baseTemplateFile = NULL;
}
} // TpfTemplate::~TpfTemplate
/**
* Sets the name of the base template for this template.
*
* @param name the base template name
*
* @return 0 on success, error code on error
*/
int TpfTemplate::setBaseTemplateName(const std::string & name)
{
m_baseTemplateName = name;
if (m_parentFile == NULL)
return -1;
// load the base template
if (m_baseTemplateFile != NULL)
{
delete m_baseTemplateFile;
m_baseTemplateFile = NULL;
}
Filename baseTemplateFileName(NULL, NULL, name.c_str(), TEMPLATE_EXTENSION);
Filename sourceTpfPath(NULL, m_parentFile->getTpfPath().c_str(), NULL, NULL);
Filename tempPath(baseTemplateFileName);
tempPath.setPath(sourceTpfPath.getPath().c_str());
tempPath.appendPath(baseTemplateFileName);
tempPath.setDrive(m_parentFile->m_fp.getFilename().getDrive().c_str());
File fp;
int i = 0;
while (!fp.exists(tempPath) && i < MAX_DIRECTORY_DEPTH)
{
sourceTpfPath.appendPath(NEXT_HIGHER_PATH);
tempPath.setPath(sourceTpfPath.getPath().c_str());
tempPath.appendPath(baseTemplateFileName);
++i;
}
if (i == MAX_DIRECTORY_DEPTH)
return -1;
m_baseTemplateFile = new TpfFile;
return m_baseTemplateFile->loadTemplate(tempPath);
} // TpfTemplate::setBaseTemplateName
/**
* Returns the template this template is derived from.
*
* @return the base template
*/
TpfTemplate * TpfTemplate::getBaseTemplate(void) const
{
if (m_baseTemplateFile != NULL)
return m_baseTemplateFile->getTemplate();
return NULL;
} // TpfTemplate::getBaseTemplate
/**
* Saves the template to an iff file.
*
* @param file file to save to
*/
void TpfTemplate::save(Iff &file)
{
UNREF(file);
} // TpfTemplate::save
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
CompilerIntegerParam *TpfTemplate::getCompilerIntegerParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getCompilerIntegerParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
FloatParam *TpfTemplate::getFloatParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getFloatParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
BoolParam *TpfTemplate::getBoolParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getBoolParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
StringParam *TpfTemplate::getStringParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getStringParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
StringIdParam *TpfTemplate::getStringIdParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getStringIdParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
VectorParam *TpfTemplate::getVectorParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getVectorParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
DynamicVariableParam *TpfTemplate::getDynamicVariableParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getDynamicVariableParam
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
StructParamOT *TpfTemplate::getStructParamOT(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getStructParamOT
/**
* Parameter accessor function for derived classes.
*
* @param name name of the parameter to get
* @param deepcheck flag to check base template if the parameter isn't loaded
* @param index array index of the parameter
*
* @return the parameter, or NULL if not found
*/
TriggerVolumeParam *TpfTemplate::getTriggerVolumeParam(const char *name, bool deepCheck, int index)
{
UNREF(name);
UNREF(deepCheck);
UNREF(index);
return NULL;
} // TpfTemplate::getTriggerVolumeParam
/**
* Initializes a structure param with the right structure type.
*
* @param param the structure param to initialize
* @param name name of the parameter to get
*/
void TpfTemplate::initStructParamOT(StructParamOT &param, const char *name)
{
UNREF(param);
UNREF(name);
} // TpfTemplate::getStructParamOT
/**
* Marks a list parameter as being an empty list.
*
* @param name name of the parameter to set
*/
void TpfTemplate::setAsEmptyList(const char *name)
{
UNREF(name);
} // TpfTemplate::setAsEmptyList
/**
* Sets the append flag for a list parameter.
*
* @param name the parameter name
*/
void TpfTemplate::setAppend(const char *name)
{
UNREF(name);
} // TpfTemplate::setAppend
/**
* Returns if the append flag is set for a list parameter.
*
* @param name the parameter name
*
* @return the flag
*/
bool TpfTemplate::isAppend(const char *name) const
{
UNREF(name);
return false;
} // TpfTemplate::isAppend
/**
* Get the length of items in a list parameter.
*
* @param name the parameter name
*
* @return number of items in the parameter list, or -1
* if the item is not a list
*/
int TpfTemplate::getListLength(const char *name) const
{
return -1;
UNREF(name);
} // TpfTemplate::getListLength
/**
* Adds a param to the loaded list.
*
* @param name the parameter name
* @param index the array index of the parameter
*/
void TpfTemplate::addLoadedParam(const std::string & name, int index)
{
std::string indexedName;
nameAndIndexToName(name, index, indexedName);
m_loadedParams.insert(indexedName);
} // TpfTemplate::addLoadedParam
/**
* Tests if a param is loaded.
*
* @param name the parameter name
* @param index the array index of the parameter
*
* @return true if the parameter is loaded, false if not
*/
bool TpfTemplate::isParamLoaded(const std::string & name, bool deepCheck, int index) const
{
std::string indexedName;
nameAndIndexToName(name, index, indexedName);
return isParamLoadedLocal(indexedName, deepCheck);
} // TpfTemplate::isParamLoaded
/**
* Adds a param to the pure virtual list.
*
* @param name the parameter name
* @param index the array index of the parameter
*/
void TpfTemplate::addPureVirtualParam(const std::string & name, int index)
{
std::string indexedName;
nameAndIndexToName(name, index, indexedName);
m_pureVirtualParams.insert(indexedName);
} // TpfTemplate::addPureVirtualParam
/**
* Tests if a param is pure virtual (defined by @derived).
*
* @param name the parameter name
* @param index the array index of the parameter
*
* @return true if the parameter is pure virtual, false if not
*/
bool TpfTemplate::isParamPureVirtual(const std::string & name, bool deepCheck, int index) const
{
std::string indexedName;
nameAndIndexToName(name, index, indexedName);
return isParamPureVirtualLocal(indexedName, deepCheck);
} // TpfTemplate::isParamPureVirtual
/**
* Converts a parameter name and index to a single name.
*
* @param name the paramter name
* @param index the parameter array index
* @param indexedName string for the modified name
*/
void TpfTemplate::nameAndIndexToName(const std::string & name, int index,
std::string & indexedName) const
{
char buffer[16];
_itoa(index, buffer, 10);
indexedName = name + "[";
indexedName += buffer;
} // TpfTemplate::nameAndIndexToName
/**
* Tests if a param is loaded.
*
* @param name the parameter name
*
* @return true if the parameter is loaded, false if not
*/
bool TpfTemplate::isParamLoadedLocal(const std::string &name, bool deepCheck) const
{
bool result = false;
std::set<std::string>::const_iterator i = m_loadedParams.find(name);
if (i != m_loadedParams.end())
{
result = true;
}
else if (deepCheck && getBaseTemplate() != NULL)
{
result = getBaseTemplate()->isParamLoadedLocal(name);
}
return result;
} // TpfTemplate::isParamLoadedLocal
/**
* Tests if a param is pure virtual (defined by @derived).
*
* @param name the parameter name
*
* @return true if the parameter is pure virtual, false if not
*/
bool TpfTemplate::isParamPureVirtualLocal(const std::string &name, bool deepCheck) const
{
bool result = false;
std::set<std::string>::const_iterator i = m_pureVirtualParams.find(name);
if (i != m_pureVirtualParams.end())
{
result = true;
}
else if (deepCheck && (getBaseTemplate() != NULL))
{
result = getBaseTemplate()->isParamPureVirtualLocal(name);
}
return result;
} // TpfTemplate::isParamPureVirtualLocal
@@ -0,0 +1,108 @@
//========================================================================
//
// TpfTemplate.h - adds extra functionality to Template for the compiler
//
// copyright 2001 Sony Online Entertainment
//
//========================================================================
#ifndef _INCLUDED_TpfTemplate_H
#define _INCLUDED_TpfTemplate_H
#include "sharedTemplateDefinition/CompilerIntegerParam.h"
#include "sharedTemplateDefinition/ObjectTemplate.h"
#include "sharedTemplateDefinition/TemplateData.h"
#include "sharedUtility/TemplateParameter.h"
#include <map>
#include <set>
#include <string>
class CompilerIntegerParam;
class TpfFile;
typedef StructParam<ObjectTemplate> StructParamOT;
//========================================================================
class TpfTemplate : public ObjectTemplate
{
public:
explicit TpfTemplate(const std::string & filename);
virtual ~TpfTemplate();
TpfFile * getParentFile(void) const;
void setParentFile(TpfFile * file);
const std::string & getBaseTemplateName(void) const;
int setBaseTemplateName(const std::string & name);
TpfTemplate * getBaseTemplate(void) const;
virtual void save(Iff &file) = 0;
static ObjectTemplate * createTemplate(Tag id);
virtual CompilerIntegerParam *getCompilerIntegerParam(const char *name, bool deepCheck = true, int index = 0);
virtual FloatParam *getFloatParam(const char *name, bool deepCheck = true, int index = 0);
virtual BoolParam *getBoolParam(const char *name, bool deepCheck = true, int index = 0);
virtual StringParam *getStringParam(const char *name, bool deepCheck = true, int index = 0);
virtual StringIdParam *getStringIdParam(const char *name, bool deepCheck = true, int index = 0);
virtual VectorParam *getVectorParam(const char *name, bool deepCheck = true, int index = 0);
virtual DynamicVariableParam *getDynamicVariableParam(const char *name, bool deepCheck = true, int index = 0);
virtual StructParamOT *getStructParamOT(const char *name, bool deepCheck = true, int index = 0);
virtual TriggerVolumeParam *getTriggerVolumeParam(const char *name, bool deepCheck = true, int index = 0);
virtual void initStructParamOT(StructParamOT &param, const char *name);
virtual void setAsEmptyList(const char *name);
virtual void setAppend(const char *name);
virtual bool isAppend(const char *name) const;
virtual int getListLength(const char *name) const;
void addLoadedParam(const std::string & name, int index = 0);
bool isParamLoaded(const std::string & name, bool deepCheck = true, int index = 0) const;
void addPureVirtualParam(const std::string & name, int index = 0);
bool isParamPureVirtual(const std::string &name, bool deepCheck = true, int index = 0) const;
protected:
TpfFile * m_parentFile;
std::string m_baseTemplateName;
TpfFile * m_baseTemplateFile;
private:
std::set<std::string> m_loadedParams;
std::set<std::string> m_pureVirtualParams;
std::map<std::string, std::vector<std::string> > m_intParamEnumMap;
void nameAndIndexToName(const std::string & name, int index, std::string & newName) const;
bool isParamLoadedLocal(const std::string &name, bool deepCheck = true) const;
bool isParamPureVirtualLocal(const std::string &name, bool deepCheck = true) const;
private:
// no copying templates
TpfTemplate(const TpfTemplate &source);
TpfTemplate & operator =(const TpfTemplate &source);
};
inline TpfFile * TpfTemplate::getParentFile(void) const
{
return m_parentFile;
}
inline void TpfTemplate::setParentFile(TpfFile * file)
{
m_parentFile = file;
}
inline const std::string & TpfTemplate::getBaseTemplateName(void) const
{
return m_baseTemplateName;
} // TpfTemplate::getBaseTemplateName
inline ObjectTemplate * TpfTemplate::createTemplate(Tag id)
{
return ObjectTemplateList::fetch(id);
}
#endif // _INCLUDED_TpfTemplate_H
@@ -0,0 +1 @@
#include "sharedTemplateDefinition/FirstSharedTemplateDefinition.h"