Replaced tabs with four spaces

This commit is contained in:
Robert Osfield
2011-06-16 08:59:48 +00:00
parent 14b12f94e5
commit d0ccbf8219
30 changed files with 5395 additions and 5395 deletions

View File

@@ -14,9 +14,9 @@
*/
/* trpage_range.cpp
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
#include <stdlib.h>
#include <stdio.h>
@@ -26,334 +26,334 @@
#include <trpage_read.h>
/* *******************
Range Methods
Range Methods
*******************
*/
trpgRange::trpgRange(void)
{
category = NULL;
subCategory = NULL;
Reset();
category = NULL;
subCategory = NULL;
Reset();
}
trpgRange::~trpgRange(void)
{
Reset();
Reset();
}
trpgRange::trpgRange(const trpgRange &in):
trpgReadWriteable(in)
{
category = NULL;
subCategory = NULL;
*this = in;
category = NULL;
subCategory = NULL;
*this = in;
}
void trpgRange::Reset(void)
{
errMess[0] = '\0';
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
errMess[0] = '\0';
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
inLod = outLod = 0.0;
priority = 0;
handle = -1;
writeHandle = false;
inLod = outLod = 0.0;
priority = 0;
handle = -1;
writeHandle = false;
}
void trpgRange::SetCategory(const char *cat,const char *subCat)
{
if (category) delete [] category;
category = NULL;
if (cat) {
category = new char[strlen(cat)+1];
strcpy(category,cat);
}
if (category) delete [] category;
category = NULL;
if (cat) {
category = new char[strlen(cat)+1];
strcpy(category,cat);
}
if (subCategory) delete [] subCategory;
subCategory = NULL;
if (subCat) {
subCategory = new char[strlen(subCat)+1];
strcpy(subCategory,subCat);
}
if (subCategory) delete [] subCategory;
subCategory = NULL;
if (subCat) {
subCategory = new char[strlen(subCat)+1];
strcpy(subCategory,subCat);
}
}
void trpgRange::GetCategory(char *cat,int catLen,char *subCat,int subCatLen) const
{
if (category && cat) {
strncpy(cat,category,catLen);
} else
*cat = 0;
if (subCategory && subCat) {
strncpy(subCat,subCategory,subCatLen);
} else
*subCat = 0;
if (category && cat) {
strncpy(cat,category,catLen);
} else
*cat = 0;
if (subCategory && subCat) {
strncpy(subCat,subCategory,subCatLen);
} else
*subCat = 0;
}
void trpgRange::SetLodInfo(double in,double out)
{
inLod = in;
outLod = out;
inLod = in;
outLod = out;
}
void trpgRange::GetLodInfo(double &in,double &out) const
{
in = inLod;
out = outLod;
in = inLod;
out = outLod;
}
void trpgRange::SetPriority(int prior)
{
priority = prior;
priority = prior;
}
void trpgRange::GetPriority(int &prior) const
{
prior = priority;
prior = priority;
}
trpgRange & trpgRange::operator = (const trpgRange &other)
{
Reset();
inLod = other.inLod;
outLod = other.outLod;
SetCategory(other.category,other.subCategory);
priority = other.priority;
handle = other.handle;
writeHandle = other.writeHandle;
return *this;
Reset();
inLod = other.inLod;
outLod = other.outLod;
SetCategory(other.category,other.subCategory);
priority = other.priority;
handle = other.handle;
writeHandle = other.writeHandle;
return *this;
}
bool trpgRange::operator == (const trpgRange &in) const
{
if (inLod != in.inLod || outLod != in.outLod)
return false;
if (priority != in.priority) return false;
if (inLod != in.inLod || outLod != in.outLod)
return false;
if (priority != in.priority) return false;
if (category && in.category) {
if (strcmp(category,in.category))
return false;
} else {
if ((category && !in.category) ||
(!category && in.category) )
return false;
}
if (category && in.category) {
if (strcmp(category,in.category))
return false;
} else {
if ((category && !in.category) ||
(!category && in.category) )
return false;
}
if (subCategory && in.subCategory) {
if (strcmp(subCategory,in.subCategory))
return false;
} else {
if ((subCategory && !in.subCategory) ||
(subCategory && in.subCategory))
return false;
}
if(handle != in.handle)
return false;
if(writeHandle != in.writeHandle)
return false;
return true;
if (subCategory && in.subCategory) {
if (strcmp(subCategory,in.subCategory))
return false;
} else {
if ((subCategory && !in.subCategory) ||
(subCategory && in.subCategory))
return false;
}
if(handle != in.handle)
return false;
if(writeHandle != in.writeHandle)
return false;
return true;
}
bool trpgRange::Write(trpgWriteBuffer &buf)
{
buf.Begin(TRPG_RANGE);
buf.Add(inLod);
buf.Add(outLod);
buf.Add(priority);
buf.Add((category ? category : ""));
buf.Add((subCategory ? subCategory : ""));
if(writeHandle) {
buf.Add((int32)handle);
}
buf.End();
buf.Begin(TRPG_RANGE);
buf.Add(inLod);
buf.Add(outLod);
buf.Add(priority);
buf.Add((category ? category : ""));
buf.Add((subCategory ? subCategory : ""));
if(writeHandle) {
buf.Add((int32)handle);
}
buf.End();
return true;
return true;
}
bool trpgRange::Read(trpgReadBuffer &buf)
{
char catStr[1024],subStr[1024];
char catStr[1024],subStr[1024];
Reset();
valid = false;
Reset();
valid = false;
try {
buf.Get(inLod);
buf.Get(outLod);
buf.Get(priority);
buf.Get(catStr,1024);
buf.Get(subStr,1024);
SetCategory(catStr,subStr);
try {
buf.Get(inLod);
buf.Get(outLod);
buf.Get(priority);
buf.Get(catStr,1024);
buf.Get(subStr,1024);
SetCategory(catStr,subStr);
// Read the handle if we can..
try {
// Read the handle if we can..
try {
int32 tempHandle;
if(buf.Get(tempHandle))
if(buf.Get(tempHandle))
{
handle = tempHandle;
}
else
{
handle = -1;
}
}
catch (...) {
handle = -1;
}
valid = true;
}
handle = -1;
}
}
catch (...) {
handle = -1;
}
valid = true;
}
catch (...) {
return false;
}
catch (...) {
return false;
}
return isValid();
return isValid();
}
/* ***************
Range Table methods
***************
Range Table methods
***************
*/
trpgRangeTable::trpgRangeTable(void)
{
valid = true;
valid = true;
}
trpgRangeTable::~trpgRangeTable(void)
{
// vector cleans up itself
// vector cleans up itself
}
void trpgRangeTable::Reset(void)
{
rangeMap.clear();
valid = true;
rangeMap.clear();
valid = true;
}
bool trpgRangeTable::GetRange(int id,trpgRange &ret) const
{
if (!isValid())
return false;
if (!isValid())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
RangeMapType::const_iterator itr = rangeMap.find(id);
if(itr == rangeMap.end()) {
return false;
}
ret = itr->second;
return true;
RangeMapType::const_iterator itr = rangeMap.find(id);
if(itr == rangeMap.end()) {
return false;
}
ret = itr->second;
return true;
}
bool trpgRangeTable::SetRange(int id,trpgRange &inRange)
{
if (!isValid())
return false;
if (!isValid())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
rangeMap[id] = inRange;
rangeMap[id] = inRange;
return true;
return true;
}
int trpgRangeTable::AddRange(trpgRange &range)
{
int handle = range.GetHandle();
if(handle==-1) {
handle = rangeMap.size();
}
rangeMap[handle] = range;
return handle;
int handle = range.GetHandle();
if(handle==-1) {
handle = rangeMap.size();
}
rangeMap[handle] = range;
return handle;
}
int trpgRangeTable::FindAddRange(trpgRange &range)
{
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
if(itr->second==range)
return itr->first;
}
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
if(itr->second==range)
return itr->first;
}
#if 0
for (int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
for (int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
#endif
return AddRange(range);
return AddRange(range);
}
bool trpgRangeTable::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeMap.size());
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeMap.size());
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
trpgRange &range = itr->second;
range.Write(buf);
}
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
trpgRange &range = itr->second;
range.Write(buf);
}
buf.End();
buf.End();
return true;
return true;
}
bool trpgRangeTable::Read(trpgReadBuffer &buf)
{
int32 numRange;
trpgToken tok;
int32 len;
valid = false;
int32 numRange;
trpgToken tok;
int32 len;
valid = false;
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
// Read in the individual range
buf.GetToken(tok,len);
if (tok != TRPG_RANGE) throw 1;
buf.PushLimit(len);
trpgRange range;
bool status = range.Read(buf);
buf.PopLimit();
if (!status) throw 1;
AddRange(range);
}
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
// Read in the individual range
buf.GetToken(tok,len);
if (tok != TRPG_RANGE) throw 1;
buf.PushLimit(len);
trpgRange range;
bool status = range.Read(buf);
buf.PopLimit();
if (!status) throw 1;
AddRange(range);
}
valid = true;
}
valid = true;
}
catch (...) {
return false;
}
catch (...) {
return false;
}
return isValid();
return isValid();
}
trpgRangeTable & trpgRangeTable::operator = (const trpgRangeTable &inTab)
{
Reset();
RangeMapType::const_iterator itr = inTab.rangeMap.begin();
for ( ; itr != inTab.rangeMap.end( ); itr++)
rangeMap[itr->first] = itr->second;
Reset();
RangeMapType::const_iterator itr = inTab.rangeMap.begin();
for ( ; itr != inTab.rangeMap.end( ); itr++)
rangeMap[itr->first] = itr->second;
#if 0
for (int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(inTab.rangeList[i]);
for (int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(inTab.rangeList[i]);
#endif
return *this;
return *this;
}