Many integer data type changes (and some temp output)

This commit is contained in:
Cekis
2021-10-15 15:25:43 -04:00
parent e8a1715dfd
commit 597d4567ae
12 changed files with 135 additions and 132 deletions
@@ -28,8 +28,8 @@
namespace IffNamespace
{
bool consumeUint32(byte const * & memory, int & length, uint32 & value);
bool isValid(byte const *memory, int length);
bool consumeUint32(byte const * & memory, int32 & length, uint32 & value);
bool isValid(byte const *memory, int32 length);
}
using namespace IffNamespace;
@@ -61,22 +61,22 @@ void Iff::install()
* @see Iff:getRawData()
*/
int Iff::calculateRawDataSize(void) const
int32 Iff::calculateRawDataSize(void) const
{
// calculate the number of data bytes actually used given the max data buffer length and the contents of the data.
if (!data)
return 0;
// -TF- this assumes any extra non-iff data within the valid iff data buffer has been zeroed out
int offset = 0;
int blockLength;
int32 offset = 0;
int32 blockLength;
uint32 tempLength;
do
{
// get block length (including tag and length field)
memcpy(&tempLength, data + offset + sizeof(Tag), sizeof(uint32));
blockLength = static_cast<int>(ntohl(tempLength)) + isizeof(Tag) + isizeof(uint32);
blockLength = static_cast<int32>(ntohl(tempLength)) + isizeof(Tag) + isizeof(uint32);
offset += blockLength;
}
while ((offset < length) && blockLength);
@@ -86,7 +86,7 @@ int Iff::calculateRawDataSize(void) const
// ======================================================================
bool IffNamespace::consumeUint32(byte const * & memory, int & length, uint32 & value)
bool IffNamespace::consumeUint32(byte const * & memory, int32 & length, uint32 & value)
{
if (length < 4)
return false;
@@ -100,7 +100,7 @@ bool IffNamespace::consumeUint32(byte const * & memory, int & length, uint32 & v
// ----------------------------------------------------------------------
bool IffNamespace::isValid(byte const *memory, int length)
bool IffNamespace::isValid(byte const *memory, int32 length)
{
if (length <= 0)
return false;
@@ -118,11 +118,11 @@ bool IffNamespace::isValid(byte const *memory, int length)
return false;
// verify the file length can contain the block's data
if ((static_cast<int>(blockLength) < 0) || (static_cast<int>(blockLength) > length))
if ((static_cast<int32>(blockLength) < 0) || (static_cast<int32>(blockLength) > length))
return false;
// verify sub-forms
int subLength = blockLength-sizeof(Tag);
int32 subLength = blockLength-sizeof(Tag);
if (blockTag == TAG_FORM && (subLength != 0 && !isValid(memory+sizeof(Tag), subLength )))
return false;
@@ -206,7 +206,7 @@ Iff::Iff(void)
* @param iffOwnsData [IN] if true, the Iff takes ownership of the buffer and deletes it during the destructor call; if false, the Iff does not attempt to delete the buffer during the destructor call
*/
Iff::Iff(int newDataSize, const byte *newData, bool iffOwnsData) :
Iff::Iff(int32 newDataSize, const byte *newData, bool iffOwnsData) :
fileName(nullptr),
maxStackDepth(DEFAULT_STACK_DEPTH),
stackDepth(0),
@@ -269,7 +269,7 @@ Iff::Iff(const char *newFileName, bool optional)
* @param clearDataBuffer [IN] if true, the iff data buffer is zeroed during construction. if false, the data buffer is uninitialized
*/
Iff::Iff(int initialSize, bool isGrowable, bool clearDataBuffer)
Iff::Iff(int32 initialSize, bool isGrowable, bool clearDataBuffer)
: fileName(nullptr),
maxStackDepth(DEFAULT_STACK_DEPTH),
stackDepth(0),
@@ -454,15 +454,15 @@ void Iff::fatal(const char *string) const
* @param bufferLength Length of the buffer to avoid overwriting memory
*/
void Iff::formatLocation(char *buffer, int bufferLength) const
void Iff::formatLocation(char *buffer, int32 bufferLength) const
{
int i, stringLength, totalLength;
int32 i, stringLength, totalLength;
NOT_NULL(buffer);
// calculate the string length
if (fileName)
stringLength = static_cast<int>(strlen(fileName));
stringLength = static_cast<int32>(strlen(fileName));
else
stringLength = 0;
@@ -506,7 +506,7 @@ void Iff::formatLocation(char *buffer, int bufferLength) const
// ----------------------------------------------------------------------
Tag Iff::getFirstTag(int depth) const
Tag Iff::getFirstTag(int32 depth) const
{
Tag t;
@@ -531,20 +531,20 @@ Tag Iff::getFirstTag(int depth) const
* @param offset [IN] offset of target block within containing block
*/
int Iff::getLength(int depth, int offset) const
int32 Iff::getLength(int32 depth, int32 offset) const
{
uint32 u;
NOT_NULL(data);
IFF_DEBUG_FATAL(stack[depth].length - stack[depth].used+offset < isizeof(Tag) + isizeof(uint32), ("read overflow"));
IFF_DEBUG_FATAL(stack[depth].length - stack[depth].used+offset < isizeof(Tag) + isizeof(int32), ("read overflow"));
memcpy(&u, data + stack[depth].start + stack[depth].used + offset + sizeof(Tag), sizeof(u));
return static_cast<int>(ntohl(u));
return static_cast<int32>(ntohl(u));
}
// ----------------------------------------------------------------------
Tag Iff::getSecondTag(int depth) const
Tag Iff::getSecondTag(int32 depth) const
{
Tag t;
@@ -573,10 +573,10 @@ Tag Iff::getSecondTag(int depth) const
* @param size Delta number of bytes
*/
void Iff::adjustDataAsNeeded(int size)
void Iff::adjustDataAsNeeded(int32 size)
{
// calculate the final required size of the data array
const int neededLength = stack[0].length + size;
const int32 neededLength = stack[0].length + size;
NOT_NULL(data);
IFF_DEBUG_FATAL(neededLength < 0, ("data size underflow"));
@@ -584,7 +584,7 @@ void Iff::adjustDataAsNeeded(int size)
// check if we need to expand the data array
if (neededLength > length)
{
int newLength;
int32 newLength;
// make sure the iff was growable
DEBUG_FATAL(!growable, ("data size overflow %d/%d", neededLength, length));
@@ -615,8 +615,8 @@ void Iff::adjustDataAsNeeded(int size)
}
// move data around to either make room or remove data
const int offset = stack[stackDepth].start + stack[stackDepth].used;
const int lengthToEnd = stack[0].length - offset;
const int32 offset = stack[stackDepth].start + stack[stackDepth].used;
const int32 lengthToEnd = stack[0].length - offset;
if (size > 0)
memmove(data+offset+size, data+offset, lengthToEnd);
else
@@ -634,13 +634,13 @@ void Iff::adjustDataAsNeeded(int size)
// update the data's idea of the block length
if (i == stackDepth && inChunk)
{
const int ui32 = static_cast<int>(htonl(static_cast<unsigned long>(stack[i].length)));
const uint32 ui32 = static_cast<uint32>(htonl(static_cast<unsigned long>(stack[i].length)));
memcpy(data+stack[i].start-sizeof(uint32), &ui32, sizeof(uint32));
}
else
{
// account for forms start beyond the first 4 data bytes, which is their real form name
const int ui32 = static_cast<int>(htonl(static_cast<unsigned long>(stack[i].length) + sizeof(Tag)));
const uint32 ui32 = static_cast<uint32>(htonl(static_cast<unsigned long>(stack[i].length) + sizeof(Tag)));
memcpy(data+stack[i].start-sizeof(Tag)-sizeof(uint32), &ui32, sizeof(uint32));
}
}
@@ -669,7 +669,7 @@ void Iff::insertIff(const Iff *iff)
adjustDataAsNeeded(iff->stack[0].length);
// compute the offset to start inserting data at
const int offset = stack[stackDepth].start + stack[stackDepth].used;
const uint32 offset = stack[stackDepth].start + stack[stackDepth].used;
// add the other iff
memcpy(data+offset, iff->data, iff->stack[0].length);
@@ -694,11 +694,11 @@ void Iff::insertIff(const Iff *iff)
void Iff::insertForm(Tag name, bool shouldEnterForm)
{
const int FORM_OVERHEAD = sizeof(Tag) + sizeof(uint32) + sizeof(Tag);
const int32 FORM_OVERHEAD = sizeof(Tag) + sizeof(uint32) + sizeof(Tag);
Tag t;
uint32 ui32;
int offset;
Tag t;
int32 ui32;
int32 offset;
NOT_NULL(data);
IFF_DEBUG_FATAL(inChunk, "inside chunk");
@@ -744,10 +744,10 @@ void Iff::insertForm(Tag name, bool shouldEnterForm)
void Iff::insertChunk(Tag name, bool shouldEnterChunk)
{
const int CHUNK_OVERHEAD = sizeof(Tag) + sizeof(uint32);
const int32 CHUNK_OVERHEAD = sizeof(Tag) + sizeof(int32);
Tag t;
int offset;
Tag t;
int32 offset;
NOT_NULL(data);
IFF_DEBUG_FATAL(inChunk, "inside chunk");
@@ -786,7 +786,7 @@ void Iff::insertChunk(Tag name, bool shouldEnterChunk)
* @param dataLength Length of the data to copy into the chunk
*/
void Iff::insertChunkData(const void *newData, int dataLength)
void Iff::insertChunkData(const void *newData, int32 dataLength)
{
NOT_NULL(data);
DEBUG_FATAL(dataLength < 0, ("dataLength < 0, %d", dataLength));
@@ -802,7 +802,7 @@ void Iff::insertChunkData(const void *newData, int dataLength)
adjustDataAsNeeded(dataLength);
// compute the offset to start inserting data at
const int offset = stack[stackDepth].start + stack[stackDepth].used;
const uint32 offset = stack[stackDepth].start + stack[stackDepth].used;
// add the size of the chunk
@@ -928,7 +928,7 @@ void Iff::insertChunkString(const Unicode::String & str)
* @param dataLength Number of bytes to delete
*/
void Iff::deleteChunkData(int dataLength)
void Iff::deleteChunkData(int32 dataLength)
{
IFF_DEBUG_FATAL(!inChunk, "not in chunk");
DEBUG_FATAL(dataLength < 0, ("dataLength to delete %d < 0", dataLength));
@@ -950,7 +950,7 @@ void Iff::deleteChunkData(int dataLength)
* @see Iff::allowNonlinearFunctions()
*/
void Iff::seekWithinChunk(int offset, SeekType seekType)
void Iff::seekWithinChunk(int32 offset, SeekType seekType)
{
DEBUG_FATAL(!nonlinear, ("nonlinear commands not permitted"));
IFF_DEBUG_FATAL(!inChunk, "not in chunk");
@@ -1018,9 +1018,9 @@ bool Iff::atEndOfForm(void) const
* @return The number of blocks left in the currently enclosing form
*/
int Iff::getNumberOfBlocksLeft(void) const
int32 Iff::getNumberOfBlocksLeft(void) const
{
int result, offset;
int32 result, offset;
IFF_DEBUG_FATAL(inChunk, "in chunk");
@@ -1038,7 +1038,7 @@ int Iff::getNumberOfBlocksLeft(void) const
* @return The tag for the specified block depth
*/
Tag Iff::getBlockName(int depth) const
Tag Iff::getBlockName(int32 depth) const
{
Tag t;
@@ -1056,7 +1056,7 @@ Tag Iff::getBlockName(int depth) const
* @return The length of the current block
*/
int Iff::getCurrentLength(void) const
int32 Iff::getCurrentLength(void) const
{
return getLength(stackDepth);
}
@@ -1385,7 +1385,7 @@ bool Iff::seek(Tag name, BlockType type)
* @see Iff::getChunkLengthLeft()
*/
int Iff::getChunkLengthTotal(int elementSize) const
int32 Iff::getChunkLengthTotal(int32 elementSize) const
{
DEBUG_FATAL(!inChunk, ("not in chunk"));
DEBUG_FATAL(stack[stackDepth].length % elementSize != 0, ("%d not a multiple of %d", stack[stackDepth].length, elementSize));
@@ -1412,17 +1412,17 @@ int Iff::getChunkLengthTotal(int elementSize) const
* @see Iff::getChunkLengthTotal()
*/
int Iff::getChunkLengthLeft(int elementSize) const
int32 Iff::getChunkLengthLeft(int32 elementSize) const
{
DEBUG_FATAL(!inChunk, ("not in chunk"));
const int left = stack[stackDepth].length - stack[stackDepth].used;
const uint32 left = stack[stackDepth].length - stack[stackDepth].used;
DEBUG_FATAL(left % elementSize != 0, ("%d not a multiple of %d", left, elementSize));
return (left / elementSize);
}
// ----------------------------------------------------------------------
void Iff::read_misc(void *readData, int readLength)
void Iff::read_misc(void *readData, uint32 readLength)
{
NOT_NULL(readData);
NOT_NULL(data);
@@ -1536,7 +1536,7 @@ Quaternion Iff::read_floatQuaternion(void)
* @param maxLength Size of the buffer
*/
void Iff::read_string(char *string, int maxLength)
void Iff::read_string(char *string, int32 maxLength)
{
NOT_NULL(string);
NOT_NULL(data);
@@ -1586,9 +1586,9 @@ char *Iff::read_string(void)
Stack &s = stack[stackDepth];
// get a pointer to the start of the source string
char *source = reinterpret_cast<char *>(data + s.start + s.used);
int maxLength = s.length - s.used;
int sourceLength = 0;
char *source = reinterpret_cast<char *>(data + s.start + s.used);
uint32 maxLength = s.length - s.used;
uint32 sourceLength = 0;
// search for the end of the string
for ( ; sourceLength < maxLength && source[sourceLength]; ++sourceLength)
@@ -1626,9 +1626,9 @@ void Iff::read_string(std::string &string)
Stack &s = stack[stackDepth];
// get a pointer to the start of the source string
char *source = reinterpret_cast<char *>(data + s.start + s.used);
int maxLength = s.length - s.used;
int sourceLength = 0;
char *source = reinterpret_cast<char *>(data + s.start + s.used);
uint32 maxLength = s.length - s.used;
uint32 sourceLength = 0;
// search for the end of the string
for ( ; sourceLength < maxLength && source[sourceLength]; ++sourceLength)
@@ -64,12 +64,12 @@ private:
char *fileName;
int maxStackDepth;
int stackDepth;
Stack *stack;
uint32 maxStackDepth;
uint32 stackDepth;
Stack *stack;
int length;
byte *data;
uint32 length;
byte *data;
bool inChunk;
bool growable;
@@ -78,16 +78,16 @@ private:
private:
Tag getFirstTag(int depth) const;
int getLength(int depth, int offset=0) const;
Tag getSecondTag(int depth) const;
Tag getBlockName(int depth) const;
Tag getFirstTag(int32 depth) const;
int32 getLength(int32 depth, int32 offset=0) const;
Tag getSecondTag(int32 depth) const;
Tag getBlockName(int32 depth) const;
void fatal(const char *string) const;
void read_misc(void *data, int length);
void growStackAsNeeded(void);
void adjustDataAsNeeded(int size);
int calculateRawDataSize(void) const;
void fatal(const char *string) const;
void read_misc(void *data, uint32 length);
void growStackAsNeeded(void);
void adjustDataAsNeeded(int32 size);
int32 calculateRawDataSize(void) const;
bool enterForm(Tag name, bool validateName, bool optional);
bool enterChunk(Tag name, bool validateName, bool optional);
@@ -102,9 +102,9 @@ public:
public:
Iff(void);
Iff(int newDataSize, const byte *newData, bool iffOwnsData=true);
Iff(int32 newDataSize, const byte *newData, bool iffOwnsData=true);
explicit Iff(const char *fileName, bool optional=false);
explicit Iff(int initialSize, bool growable=true, bool clearDataBuffer=false);
explicit Iff(int32 initialSize, bool growable=true, bool clearDataBuffer=false);
~Iff(void);
const char* getFileName (void) const;
@@ -120,15 +120,15 @@ public:
// raw data retrieval
const byte *getRawData(void) const;
int getRawDataSize(void) const;
int32 getRawDataSize(void) const;
void formatLocation(char *buffer, int bufferLength) const;
void formatLocation(char *buffer, int32 bufferLength) const;
// creating forms and chunk
void insertIff(const Iff *iff);
void insertForm(Tag name, bool shouldEnterForm=true);
void insertChunk(Tag name, bool shouldEnterChunk=true);
void insertChunkData(const void *data, int length);
void insertChunkData(const void *data, int32 length);
void insertChunkString(const char *string);
void insertChunkString(const Unicode::String & str);
void insertChunkFloatVector(const Vector &vector);
@@ -136,7 +136,7 @@ public:
void insertChunkFloatTransform(const Transform &transform);
void insertChunkFloatQuaternion(const Quaternion &quaternion);
template <class T> void insertChunkArray(T const * array, int size)
template <class T> void insertChunkArray(T const * array, int32 size)
{
insertChunkData(array,sizeof(T) * size);
}
@@ -147,26 +147,26 @@ public:
}
// delete data from the chunk data
void deleteChunkData(int length);
void deleteChunkData(int32 length);
// nonlinear functions
void allowNonlinearFunctions(void);
void seekWithinChunk(int offset, SeekType seekType);
void seekWithinChunk(int32 offset, SeekType seekType);
void goToTopOfForm(void);
// get information on current block
Tag getCurrentName(void) const;
int getCurrentLength(void) const;
int32 getCurrentLength(void) const;
bool isCurrentChunk(void) const;
bool isCurrentForm(void) const;
bool atEndOfForm(void) const;
// get the number of blocks left in the current enclosing form
int getNumberOfBlocksLeft(void) const;
int32 getNumberOfBlocksLeft(void) const;
// get information about the number of bytes in the current chunk
int getChunkLengthTotal(int elementSize=1) const;
int getChunkLengthLeft(int elementSize=1) const;
int32 getChunkLengthTotal(int32 elementSize=1) const;
int32 getChunkLengthLeft(int32 elementSize=1) const;
// enter/exit forms
void enterForm(void);
@@ -240,7 +240,7 @@ public:
uint32 *readRest_uint32(void);
char *readRest_char (void);
void read_string(char *string, int maxLength);
void read_string(char *string, int32 maxLength);
char *read_string(void);
void read_string(std::string &string);
@@ -274,7 +274,7 @@ inline const char* Iff::getFileName (void) const
//
// Iff:getRawData()
inline int Iff::getRawDataSize(void) const
inline int32 Iff::getRawDataSize(void) const
{
if (!data || !stack)
return 0;
@@ -1164,13 +1164,13 @@ inline void Iff::readRest_char(char *array, int numberOfElements)
* will call Fatal in debug compiles, but its behavior is undefined in release
* compiles.
*
* @return Dyanmically allocated array containing the data
* @return Dynamically allocated array containing the data
* @see Iff::read_*()
*/
inline int8 *Iff::readRest_int8(void)
{
const int count = getChunkLengthLeft(isizeof(int8));
const int32 count = getChunkLengthLeft(isizeof(int8));
int8 *const array = new int8[static_cast<size_t>(count)];
read_int8(count, array);
return array;
@@ -1198,7 +1198,7 @@ inline int8 *Iff::readRest_int8(void)
inline int16 *Iff::readRest_int16(void)
{
const int count = getChunkLengthLeft(isizeof(int16));
const int32 count = getChunkLengthLeft(isizeof(int16));
int16 * const array = new int16[static_cast<size_t>(count)];
read_int16(count, array);
return array;
@@ -1226,7 +1226,7 @@ inline int16 *Iff::readRest_int16(void)
inline int32 *Iff::readRest_int32(void)
{
const int count = getChunkLengthLeft(isizeof(int32));
const int32 count = getChunkLengthLeft(isizeof(int32));
int32 * const array = new int32[static_cast<size_t>(count)];
read_int32(count, array);
return array;
@@ -1254,7 +1254,7 @@ inline int32 *Iff::readRest_int32(void)
inline uint8 *Iff::readRest_uint8(void)
{
const int count = getChunkLengthLeft(isizeof(uint8));
const int32 count = getChunkLengthLeft(isizeof(uint8));
uint8 * const array = new uint8[static_cast<size_t>(count)];
read_uint8(count, array);
return array;
@@ -1282,7 +1282,7 @@ inline uint8 *Iff::readRest_uint8(void)
inline uint16 *Iff::readRest_uint16(void)
{
const int count = getChunkLengthLeft(isizeof(uint16));
const int32 count = getChunkLengthLeft(isizeof(uint16));
uint16 * const array = new uint16[static_cast<size_t>(count)];
read_uint16(count, array);
return array;
@@ -1310,7 +1310,7 @@ inline uint16 *Iff::readRest_uint16(void)
inline uint32 *Iff::readRest_uint32(void)
{
const int count = getChunkLengthLeft(isizeof(uint32));
const int32 count = getChunkLengthLeft(isizeof(uint32));
uint32 * const array = new uint32[static_cast<size_t>(count)];
read_uint32(count, array);
return array;
@@ -1338,7 +1338,7 @@ inline uint32 *Iff::readRest_uint32(void)
inline char *Iff::readRest_char(void)
{
const int count = getChunkLengthLeft(isizeof(char));
const int32 count = getChunkLengthLeft(isizeof(char));
char * const array = new char[static_cast<size_t>(count)];
read_char(count, array);
return array;
@@ -43,7 +43,7 @@ bool Md5::Value::operator !=(Value const &rhs) const
// ----------------------------------------------------------------------
void Md5::Value::format(char *buffer, int bufferLength) const
void Md5::Value::format(char *buffer, int32 bufferLength) const
{
//not referenced in release build
UNREF(bufferLength);
@@ -60,7 +60,7 @@ Md5::Value Md5::calculate(const char *string)
// ----------------------------------------------------------------------
Md5::Value Md5::calculate(void const *data, int length)
Md5::Value Md5::calculate(void const *data, int32 length)
{
Md5 md5;
md5.update(data, length);
@@ -94,7 +94,7 @@ void Md5::reset()
// ----------------------------------------------------------------------
void Md5::update(void const *data, int length)
void Md5::update(void const *data, int32 length)
{
m_totalLength += length;
@@ -111,7 +111,7 @@ void Md5::update(void const *data, int length)
else
{
// figure out how many bytes to copy into the temp buffer
int bytesToCopy = BUFFER_SIZE - m_bufferedBytes;
int32 bytesToCopy = BUFFER_SIZE - m_bufferedBytes;
if (length < bytesToCopy)
bytesToCopy = length;
@@ -33,7 +33,7 @@ public:
bool operator ==(Value const &rhs) const;
bool operator !=(Value const &rhs) const;
void format(char *buffer, int bufferLength) const;
void format(char *buffer, int32 bufferLength) const;
void *getData();
@@ -45,14 +45,14 @@ public:
public:
static Value calculate(const char *string);
static Value calculate(const void *data, int len);
static Value calculate(const void *data, int32 len);
public:
Md5();
void reset();
void update(void const *data, int len);
void update(void const *data, int32 len);
void finish();
Value getValue() const;
@@ -75,11 +75,11 @@ private:
BUFFER_SIZE = 64
};
uint32 m_data[4];
byte m_buffer[BUFFER_SIZE];
int m_bufferedBytes;
int m_totalLength;
bool m_finished;
uint32 m_data[4];
byte m_buffer[BUFFER_SIZE];
int32 m_bufferedBytes;
int32 m_totalLength;
bool m_finished;
public:
@@ -226,7 +226,7 @@ inline void imemcpy(void *destination, const void *source, int length)
* @param length Number of bytes to copy
*/
inline void *memmove(void *destination, const void *source, int length)
inline void *memmove(void *destination, const void *source, int32 length)
{
DEBUG_FATAL(!destination, ("nullptr destination arg"));
DEBUG_FATAL(!source, ("nullptr source arg"));
@@ -171,12 +171,12 @@ DataTableColumnType const &DataTable::getDataTypeForColumn(const std::string& co
DataTableColumnType const &DataTable::getDataTypeForColumn(int column) const
{
DEBUG_FATAL(column < 0 || column >= getNumColumns(), ("DataTable [%s] getDataTypeForColumn(): Invalid col number [%d]. Cols=[%d]\n", m_name.c_str(), column, getNumColumns()));
return *m_types[static_cast<size_t>(column)];
return *m_types[static_cast<size_t>(column)];
}
//----------------------------------------------------------------------------
int DataTable::getIntValue(const std::string & column, int row) const
int32_t DataTable::getIntValue(const std::string & column, int row) const
{
int const columnIndex = findColumnNumber(column);
DEBUG_FATAL(columnIndex < 0 || columnIndex >= getNumColumns(), ("DataTable [%s] getIntValue(): Column name [%s] is invalid\n", m_name.c_str(), column.c_str()));
@@ -185,7 +185,7 @@ int DataTable::getIntValue(const std::string & column, int row) const
//----------------------------------------------------------------------------
int DataTable::getIntValue(int column, int row) const
int32_t DataTable::getIntValue(int column, int row) const
{
DEBUG_FATAL(row < 0 || row >= getNumRows(), ("DataTable [%s] getIntValue(): Invalid row number [%d]. Rows=[%d]\n", m_name.c_str(), row, getNumRows()));
DEBUG_FATAL(column < 0 || column >= getNumColumns(), ("DataTable [%s] getIntValue(): Invalid col number [%d]. Cols=[%d]\n", m_name.c_str(), column, getNumColumns()));
@@ -210,7 +210,7 @@ int DataTable::getIntValue(int column, int row) const
//----------------------------------------------------------------------------
int DataTable::getIntDefaultForColumn(const std::string & column) const
int32_t DataTable::getIntDefaultForColumn(const std::string & column) const
{
int const columnIndex = findColumnNumber(column);
DEBUG_FATAL(columnIndex < 0 || columnIndex >= getNumColumns(), ("DataTable [%s] getIntDefaultForColumn(): Invalid col number [%d]. Cols=[%d]\n", m_name.c_str(), columnIndex, getNumColumns()));
@@ -219,7 +219,7 @@ int DataTable::getIntDefaultForColumn(const std::string & column) const
//----------------------------------------------------------------------------
int DataTable::getIntDefaultForColumn(int column) const
int32_t DataTable::getIntDefaultForColumn(int column) const
{
DEBUG_FATAL(column < 0 || column >= getNumColumns(), ("DataTable [%s] getIntDefaultForColumn(): Invalid col number [%d]. Cols=[%d]\n", m_name.c_str(), column, getNumColumns()));
DEBUG_FATAL(m_types[static_cast<size_t>(column)]->getBasicType() != DataTableColumnType::DT_Int, ("Wrong data type for column %d.", column));
@@ -317,7 +317,7 @@ std::string DataTable::getStringDefaultForColumn(int column) const
//----------------------------------------------------------------------------
void DataTable::getIntColumn(const std::string& column, std::vector<int>& returnVector) const
void DataTable::getIntColumn(const std::string& column, std::vector<int32_t>& returnVector) const
{
int const columnIndex = findColumnNumber(column);
DEBUG_FATAL(columnIndex < 0 || columnIndex >= getNumColumns(), ("DataTable Column [%s] is invalid", column.c_str()));
@@ -353,7 +353,7 @@ void DataTable::getStringColumn(const std::string& column, std::vector<const cha
//----------------------------------------------------------------------------
void DataTable::getIntColumn(int column, std::vector<int>& returnVector) const
void DataTable::getIntColumn(int column, std::vector<int32_t>& returnVector) const
{
returnVector.clear();
for (int i = 0; i < getNumRows(); ++i)
@@ -405,7 +405,7 @@ void DataTable::_readCell(Iff & iff, int column, int row)
{
case DataTableColumnType::DT_Int:
{
int tmp = iff.read_int32();
int32 tmp = iff.read_int32();
new (cell) DataTableCell(tmp);
break;
@@ -31,10 +31,10 @@ public:
DataTableColumnType const &getDataTypeForColumn(const std::string& column) const;
DataTableColumnType const &getDataTypeForColumn(int column) const;
int getIntValue(const std::string & column, int row) const;
int getIntValue(int column, int row) const;
int getIntDefaultForColumn(const std::string & column) const;
int getIntDefaultForColumn(int column) const;
int32_t getIntValue(const std::string & column, int row) const;
int32_t getIntValue(int column, int row) const;
int32_t getIntDefaultForColumn(const std::string & column) const;
int32_t getIntDefaultForColumn(int column) const;
float getFloatValue(const std::string & column, int row) const;
float getFloatValue(int column, int row) const;
float getFloatDefaultForColumn(const std::string & column) const;
@@ -44,11 +44,11 @@ public:
std::string getStringDefaultForColumn(const std::string & column) const;
std::string getStringDefaultForColumn(int column) const;
void getIntColumn(const std::string& column, std::vector<int>& returnVector) const;
void getIntColumn(const std::string& column, std::vector<int32_t>& returnVector) const;
void getIntColumn(const std::string& column, std::vector<long>& returnVector) const;
void getFloatColumn(const std::string& column, std::vector<float>& returnVector) const;
void getStringColumn(const std::string& column, std::vector<const char *>& returnVector) const;
void getIntColumn(int column, std::vector<int>& returnVector) const;
void getIntColumn(int column, std::vector<int32_t>& returnVector) const;
void getIntColumn(int column, std::vector<long>& returnVector) const;
void getFloatColumn(int column, std::vector<float>& returnVector) const;
void getStringColumn(int column, std::vector<const char *>& returnVector) const;
@@ -86,8 +86,8 @@ private:
typedef std::vector<const DataTableColumnType *> DataTableColumnTypeVector;
typedef std::unordered_map<std::string /*column name*/, int /*column index*/> ColumnIndexMap;
int m_numRows;
int m_numCols;
int32_t m_numRows;
int32_t m_numCols;
DataTableCell const * m_cells;
std::vector<std::string> m_columns;
mutable std::vector<void *> m_index;
@@ -55,7 +55,7 @@ void DataTableCell::operator delete(void *pointer)
// ----------------------------------------------------------------------
DataTableCell::DataTableCell(int value)
DataTableCell::DataTableCell(int32 value)
: m_type(CT_int)
{
m_value.m_i=value;
@@ -31,16 +31,16 @@ public:
,CT_float
};
explicit DataTableCell(int value);
explicit DataTableCell(int32 value);
explicit DataTableCell(float value);
explicit DataTableCell(const char *value);
~DataTableCell();
CellType getType() const { return m_type; }
int getIntValue() const { return m_value.m_i; }
int32_t getIntValue() const { return m_value.m_i; }
float getFloatValue() const { return m_value.m_f; }
const char *getStringValue() const;
int getStringValueCrc() const { return m_value.m_s.m_crc; }
int32_t getStringValueCrc() const { return m_value.m_s.m_crc; }
private:
const CellType m_type;
@@ -48,12 +48,12 @@ private:
{
union
{
int m_i;
float m_f;
int32_t m_i;
float m_f;
struct
{
const char *m_sz;
int m_crc;
int32_t m_crc;
} m_s;
};
} m_value;
@@ -148,7 +148,7 @@ DataTableColumnType::DataTableColumnType(std::string const &desc) :
std::string::size_type endPos = enumList.find(',');
std::string label = enumList.substr(0, eqPos);
std::string val = enumList.substr(eqPos+1, endPos-eqPos-1);
(*m_enumMap)[label] = static_cast<int>(strtol(val.c_str(), nullptr, 0));
(*m_enumMap)[label] = static_cast<uint32>(strtol(val.c_str(), nullptr, 0));
enumList.erase(0, endPos+1);
}
// assure the default is a member of the enumeration
@@ -213,7 +213,7 @@ DataTableColumnType::DataTableColumnType(std::string const &desc) :
{
std::string key = enumTable->getStringValue(0, x);
Unicode::trim(key);
int value = enumTable->getIntValue(1,x);
uint32 value = enumTable->getIntValue(1,x);
if (x==0)
firstKey = key;
(*m_enumMap)[key] = value;
@@ -247,7 +247,7 @@ void DataTableColumnType::createDefaultCell()
switch(m_basicType)
{
case DT_Int:
m_defaultCell = new DataTableCell(static_cast<int>(strtol(value.c_str(), nullptr, 0)));
m_defaultCell = new DataTableCell(static_cast<int32>(strtol(value.c_str(), nullptr, 0)));
break;
case DT_Float:
m_defaultCell = new DataTableCell(static_cast<float>(atof(value.c_str())));
@@ -327,7 +327,6 @@ DataTableColumnType::DataType DataTableColumnType::getBasicType() const
}
// ----------------------------------------------------------------------
bool DataTableColumnType::lookupEnum(std::string const &label, int &result) const
{
NOT_NULL(m_enumMap);
@@ -340,6 +339,9 @@ bool DataTableColumnType::lookupEnum(std::string const &label, int &result) cons
result = (*i).second;
return true;
}
for(std::map<std::string, uint32>::const_iterator it = m_enumMap->begin(); it != m_enumMap->end(); ++it) {
WARNING(true,("Map Value: %s; ", it->first.c_str()));
}
return false;
}
@@ -417,6 +419,7 @@ bool DataTableColumnType::mangleValue(std::string &value) const
// than default values
if (m_basicType != DT_Int || m_type == DT_Int)
return true;
// complex type which needs mangling
switch (m_type)
{
@@ -56,7 +56,7 @@ private:
DataType m_type;
DataType m_basicType;
std::string m_defaultValue;
typedef std::map<std::string, int> StringIntMap;
typedef std::map<std::string, uint32> StringIntMap;
StringIntMap * m_enumMap;
DataTableCell * m_defaultCell;
};
@@ -728,7 +728,7 @@ DataTableCell *DataTableWriter::_getNewCell(DataTableColumnType const &columnTyp
switch (columnType.getBasicType())
{
case DataTableColumnType::DT_Int:
return new DataTableCell(static_cast<int>(strtol(value.c_str(), nullptr, 0)));
return new DataTableCell(static_cast<int32>(strtol(value.c_str(), nullptr, 0)));
break;
case DataTableColumnType::DT_Float:
return new DataTableCell(static_cast<float>(atof(value.c_str())));