|
-
July 5th, 2007, 01:18 PM
#3
Re: STL issues with sort()?
Ya, I've been thinking about that. I don't use this across threads or anything, but maybe something totally unrelated has ripped into the memory, I am putting some bounds checking software on here and seeing what that points to.
Anyways, here's the struct I use:
Code:
typedef struct tagSORTED_LIST
{
RCP_JOB_INFO::point_info pi;
unsigned long job_idx; // Only valid for sorting a list of RCP_JOB_INFOs.
inline tagSORTED_LIST &operator = (tagSORTED_LIST _v)
{
if ( this != &_v )
memcpy(this, &_v, sizeof(tagSORTED_LIST));
return *this;
}
inline bool operator < (tagSORTED_LIST _v)
{
return (_v > *this);
}
inline bool operator > (tagSORTED_LIST _v)
{
bool result;
result = false;
if ( (pi.has_sub == 0) && (_v.pi.has_sub == 0) )
{
if ( pi.main_adr == _v.pi.main_adr )
{
if ( pi.num > _v.pi.num )
result = true;
else
result = false;
}
else if ( pi.main_adr > _v.pi.main_adr )
result = true;
else
result = false;
}
else if ( (pi.has_sub == 0) && (_v.pi.has_sub == 1) )
{
if ( pi.main_adr > _v.pi.main_adr )
result = true;
else
result = false;
}
else if ( (pi.has_sub == 1) && (_v.pi.has_sub == 1) )
{
if ( pi.main_adr == _v.pi.main_adr )
{
if ( pi.sub_a == _v.pi.sub_a )
{
if ( pi.sub_adr > _v.pi.sub_adr )
result = true;
else if ( pi.sub_adr == _v.pi.sub_adr )
{
if ( pi.num > _v.pi.num )
result = true;
else
result = false;
}
else
result = false;
}
else if ( pi.sub_a == 0 && _v.pi.sub_a == 1 )
result = true;
else // if ( pi.sub_a == 1 && _v.pi.sub_a == 0 )
result = false;
}
else if ( pi.main_adr > _v.pi.main_adr )
result = true;
}
else // pi.has_sub == 1 && _v.pi.has_sub == 0
{
if ( pi.main_adr >= _v.pi.main_adr )
result = true;
else
result = false;
}
return result;
}
inline bool operator == (tagSORTED_LIST)
{
return false;
}
inline bool operator != (tagSORTED_LIST)
{
return true;
}
} SORTED_LIST;
RCP_JOB_INFO: oint_info pi; is just another 32bit number with nit fields, no thing strange or unusual about it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|