Operator abuse?
508
0
Advertisement
So, I'm at work... and if we ignore the fact I'm connected to my home machine and the other tab I have open in IE is the archives of Down To Earth we can keep beliving this [grin]
So, with my now chemically enhanced brain I figure it's a good time to work out what some code is doing and see where I can improve it. Yesterday I went into a class and removed aload of dynamic allocation where it wasn't required and replaced the usage of Borland's TList class with a nice standard std::vector; the thing it was holding was only a struct with an int and a string in it anyways and to get the databack you had to cast from a void * to a pointer to the struct.
I came in today with the aim to find out where my 'return by value' instead of 'returning a pointer' changes would break things, I rebuilt the project and it compiled first time. Turns out the function which returned a pointer was never used in the project o.O The function just below that duplicated what it did to just extract the filename anyways so in the end I just reimplimented it in terms of the unused function.
Next I turned my attention to this line;
NumberString = StringReplace( NumberString, this->FileExtension, "", TReplaceFlags() << rfReplaceAll);
Namely, wtf is going on with that last parameter, because it made no sense to me. However, the first problem was finding out what parameters the call expected as StringReplace in Borland's help doesn't have an extry for it. *sigh*
A bit of searching later and we get this;
extern PACKAGE AnsiString __fastcall StringReplace(const AnsiString S, const AnsiString OldPattern, const AnsiString NewPattern, TReplaceFlags Flags);
OK, that makes sense, sort of... time to go looking for the definition of TReplaceFlags...
That give us;
typedef Set TReplaceFlags;
which in turn references;
enum SysUtils__94 { rfReplaceAll, rfIgnoreCase };
So, next we go looking for the definition of 'Set', which leads us to 'operator <<' being used to add values to the set o.O
So, looking back at our original function call (NumberString = StringReplace( NumberString, this->FileExtension, "", TReplaceFlags() << rfReplaceAll);) it seems that we create an empty set of flags and then add rfReplaceAll to that set.
Of course, none of this was clear at the call site and I'm sure there are easier ways to send in a series of flags or at least a better name for the container would have been nice.
Have I mentioned of late how much I hate this Borland IDE? [sad]
So, with my now chemically enhanced brain I figure it's a good time to work out what some code is doing and see where I can improve it. Yesterday I went into a class and removed aload of dynamic allocation where it wasn't required and replaced the usage of Borland's TList class with a nice standard std::vector; the thing it was holding was only a struct with an int and a string in it anyways and to get the databack you had to cast from a void * to a pointer to the struct.
I came in today with the aim to find out where my 'return by value' instead of 'returning a pointer' changes would break things, I rebuilt the project and it compiled first time. Turns out the function which returned a pointer was never used in the project o.O The function just below that duplicated what it did to just extract the filename anyways so in the end I just reimplimented it in terms of the unused function.
Next I turned my attention to this line;
NumberString = StringReplace( NumberString, this->FileExtension, "", TReplaceFlags() << rfReplaceAll);
Namely, wtf is going on with that last parameter, because it made no sense to me. However, the first problem was finding out what parameters the call expected as StringReplace in Borland's help doesn't have an extry for it. *sigh*
A bit of searching later and we get this;
extern PACKAGE AnsiString __fastcall StringReplace(const AnsiString S, const AnsiString OldPattern, const AnsiString NewPattern, TReplaceFlags Flags);
OK, that makes sense, sort of... time to go looking for the definition of TReplaceFlags...
That give us;
typedef Set TReplaceFlags;
which in turn references;
enum SysUtils__94 { rfReplaceAll, rfIgnoreCase };
So, next we go looking for the definition of 'Set', which leads us to 'operator <<' being used to add values to the set o.O
So, looking back at our original function call (NumberString = StringReplace( NumberString, this->FileExtension, "", TReplaceFlags() << rfReplaceAll);) it seems that we create an empty set of flags and then add rfReplaceAll to that set.
Of course, none of this was clear at the call site and I'm sure there are easier ways to send in a series of flags or at least a better name for the container would have been nice.
Have I mentioned of late how much I hate this Borland IDE? [sad]
Advertisement
Advertisement
Advertisement
Discussion