S
sccr13plyr
Hello,
I do not know if this forum is the right place to post this message.
If it is not, please let me know a better place to get my question
addressed. I am an old C programmer that became a self-taught C++
programmer. So, the following may simply be my ignorance of the C++
language.
I am at a site that has an older application written in C that has
over time been migrated to C++. This is a high performance
application that processes a 100 million records a day that are then
broken down into component transactions. We have a set of algorithms
that process these transactions and have a lot of duplicate logic.
We want to add functionality, simplify the code, and keep the
performance.
I prototyped out the following:
#include <stdio.h> // streams can be discussed another time...
class BaseAlgorithm
{
public: virtual ~BaseAlgorithm (){}
public: inline void Display (const int id, const char* output)
{
(void) printf ("Algorithm: %d - %s\n", id, output);
}
};
template<int id, bool checkPrice, bool specificCode, bool currTran>
class GenericAlgorithm : public BaseAlgorithm
{
private: static const int algorithmId_ = id;
private: static const bool checkPriceChanged_ = checkPrice;
private: static const bool specificCode_ = specificCode;
private: static const bool currentTransOnly_ = currTran;
public: GenericAlgorithm (){}
public: virtual ~GenericAlgorithm (){}
public: inline void GenericLogic (int* data, int* env, char*
retInfo)
{
if (data == NULL)
if (env == NULL)
if (retInfo == NULL)
{
//
}
if (checkPriceChanged_)
{
if (specificCode_)
{
if (currentTransOnly_)
{
char v1[1000][1000];
v1[999][999] = 'd';
if (v1[999][999] == 'd')
{
}
Display (algorithmId_, "Check Price,
Specific Code, Current Tran");
}
else
{
Display (algorithmId_, "Check Price,
Specific Code, All Trans");
}
}
else
{
if (currentTransOnly_)
{
Display (algorithmId_, "Check Price, All
Code, Current Tran");
}
else
{
Display (algorithmId_, "Check Price, All
Code, All Tran");
}
}
}
else
{
if (specificCode_)
{
if (currentTransOnly_)
{
Display (algorithmId_, "Ignore Price,
Specific Code, Current Tran");
}
else
{
Display (algorithmId_, "Ignore Price,
Specific Code, All Trans");
}
}
else
{
if (currentTransOnly_)
{
Display (algorithmId_, "Ignore Price, All
Code, Current Tran");
}
else
{
Display (algorithmId_, "Ignore Price, All
Code, All Trans");
}
}
}
}
};
#include <stdlib.h>
int main (void)
{
GenericAlgorithm<159, true, true, true> test;
test.GenericLogic (NULL, NULL, NULL);
GenericAlgorithm<246, true, false, false> *oldTest = new
GenericAlgorithm<246, true, false, false>;
oldTest->GenericLogic (NULL, NULL, NULL);
return EXIT_SUCCESS;
}
This approach would collapse the three algorithms into one body of
logic in GenericLogic. By using constants, my desire is to have the
compiler create two separate versions of GenericLogic (one for each of
the new class declarations in main), removing code (and comparisons)
that would never need to be used.
Should I expect that the compiler is actually removing unreachable
code? Would this be compiler specific or I should be utilizing a
different C++ language construct? Also, the pointer declaration and
initialization becomes a little bulky, something I can do there?
Thanks in advance for your assistance, and sorry if this is not the
right venue...
sccr13plyr
I do not know if this forum is the right place to post this message.
If it is not, please let me know a better place to get my question
addressed. I am an old C programmer that became a self-taught C++
programmer. So, the following may simply be my ignorance of the C++
language.
I am at a site that has an older application written in C that has
over time been migrated to C++. This is a high performance
application that processes a 100 million records a day that are then
broken down into component transactions. We have a set of algorithms
that process these transactions and have a lot of duplicate logic.
We want to add functionality, simplify the code, and keep the
performance.
I prototyped out the following:
#include <stdio.h> // streams can be discussed another time...
class BaseAlgorithm
{
public: virtual ~BaseAlgorithm (){}
public: inline void Display (const int id, const char* output)
{
(void) printf ("Algorithm: %d - %s\n", id, output);
}
};
template<int id, bool checkPrice, bool specificCode, bool currTran>
class GenericAlgorithm : public BaseAlgorithm
{
private: static const int algorithmId_ = id;
private: static const bool checkPriceChanged_ = checkPrice;
private: static const bool specificCode_ = specificCode;
private: static const bool currentTransOnly_ = currTran;
public: GenericAlgorithm (){}
public: virtual ~GenericAlgorithm (){}
public: inline void GenericLogic (int* data, int* env, char*
retInfo)
{
if (data == NULL)
if (env == NULL)
if (retInfo == NULL)
{
//
}
if (checkPriceChanged_)
{
if (specificCode_)
{
if (currentTransOnly_)
{
char v1[1000][1000];
v1[999][999] = 'd';
if (v1[999][999] == 'd')
{
}
Display (algorithmId_, "Check Price,
Specific Code, Current Tran");
}
else
{
Display (algorithmId_, "Check Price,
Specific Code, All Trans");
}
}
else
{
if (currentTransOnly_)
{
Display (algorithmId_, "Check Price, All
Code, Current Tran");
}
else
{
Display (algorithmId_, "Check Price, All
Code, All Tran");
}
}
}
else
{
if (specificCode_)
{
if (currentTransOnly_)
{
Display (algorithmId_, "Ignore Price,
Specific Code, Current Tran");
}
else
{
Display (algorithmId_, "Ignore Price,
Specific Code, All Trans");
}
}
else
{
if (currentTransOnly_)
{
Display (algorithmId_, "Ignore Price, All
Code, Current Tran");
}
else
{
Display (algorithmId_, "Ignore Price, All
Code, All Trans");
}
}
}
}
};
#include <stdlib.h>
int main (void)
{
GenericAlgorithm<159, true, true, true> test;
test.GenericLogic (NULL, NULL, NULL);
GenericAlgorithm<246, true, false, false> *oldTest = new
GenericAlgorithm<246, true, false, false>;
oldTest->GenericLogic (NULL, NULL, NULL);
return EXIT_SUCCESS;
}
This approach would collapse the three algorithms into one body of
logic in GenericLogic. By using constants, my desire is to have the
compiler create two separate versions of GenericLogic (one for each of
the new class declarations in main), removing code (and comparisons)
that would never need to be used.
Should I expect that the compiler is actually removing unreachable
code? Would this be compiler specific or I should be utilizing a
different C++ language construct? Also, the pointer declaration and
initialization becomes a little bulky, something I can do there?
Thanks in advance for your assistance, and sorry if this is not the
right venue...
sccr13plyr