git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@92 d34b734f-a00e-4b39-a726-e4eeb87269abadeniz_1
@@ -26,7 +26,7 @@ | |||
#include <iostream> | |||
#include <string> | |||
using namespace std; | |||
namespace CodeDweller { | |||
const int DefaultExitCode = EXIT_FAILURE; // Use this when no code is provided. | |||
@@ -34,62 +34,62 @@ class AbortCheck { | |||
private: | |||
const string myDescription; // This is what I have to say. | |||
const std::string myDescription; // This is what I have to say. | |||
public: | |||
AbortCheck(const string& Text) : myDescription(Text) {} // I am constructed with a description | |||
AbortCheck(const std::string& Text) : myDescription(Text) {} // I am constructed with a description | |||
void operator()(bool X) const { // Apply me like assert(exp) | |||
if(false == X) { // If the expression is false then we | |||
cerr << myDescription << endl; // failed the check so we display our | |||
std::cerr << myDescription << std::endl; // failed the check so we display our | |||
abort(); // description and abort. | |||
} | |||
} | |||
const string Description() { return myDescription; } // You can ask for my Description. | |||
const std::string Description() { return myDescription; } // You can ask for my Description. | |||
}; | |||
class AbortFault { // If this fault occurs we will abort. | |||
private: | |||
const string myDescription; // This is what I have to say. | |||
const std::string myDescription; // This is what I have to say. | |||
public: | |||
AbortFault(const string& Text) : myDescription(Text) {} // I am constructed with a description | |||
AbortFault(const std::string& Text) : myDescription(Text) {} // I am constructed with a description | |||
void operator()(bool X) const { // Apply me like assert(! exp) | |||
if(true == X) { // If the expression is true then we | |||
cerr << myDescription << endl; // have a fault so we display our fault | |||
std::cerr << myDescription << std::endl; // have a fault so we display our fault | |||
abort(); // description and abort. | |||
} | |||
} | |||
const string Description() const { return myDescription; } // You can ask for my Description. | |||
const std::string Description() const { return myDescription; } // You can ask for my Description. | |||
}; | |||
class ExitCheck { // If this check is false we will exit. | |||
private: | |||
const string myDescription; // This is what I have to say. | |||
const std::string myDescription; // This is what I have to say. | |||
const int myExitCode; // This is what I send to exit(). | |||
public: | |||
ExitCheck(const string& Text, int Code=DefaultExitCode) : // I am constructed with a description | |||
ExitCheck(const std::string& Text, int Code=DefaultExitCode) : // I am constructed with a description | |||
myDescription(Text), myExitCode(Code) {} // and (optionlly) an exit code. | |||
void operator()(bool X) const { // Apply me like assert(exp) | |||
if(false == X) { // If the expression is false then we | |||
cerr << myDescription << endl; // failed the check so we display our | |||
std::cerr << myDescription << std::endl; // failed the check so we display our | |||
exit(myExitCode); // description and exit with our code. | |||
} | |||
} | |||
const string Description() { return myDescription; } // You can ask for my Description. | |||
const std::string Description() { return myDescription; } // You can ask for my Description. | |||
const int ExitCode() { return myExitCode; } // You can ask for my ExitCode. | |||
}; | |||
@@ -97,30 +97,30 @@ class ExitFault { | |||
private: | |||
const string myDescription; // This is what I have to say. | |||
const std::string myDescription; // This is what I have to say. | |||
const int myExitCode; // This is what I send to exit(). | |||
public: | |||
ExitFault(const string& Text, int Code=DefaultExitCode) : // I am constructed with a description | |||
ExitFault(const std::string& Text, int Code=DefaultExitCode) : // I am constructed with a description | |||
myDescription(Text), myExitCode(Code) {} // and (optionlly) an exit code. | |||
void operator()(bool X) const { // Apply me like assert(! exp) | |||
if(true == X) { // If the expression is true then we | |||
cerr << myDescription << endl; // have a fault so we display our fault | |||
std::cerr << myDescription << std::endl; // have a fault so we display our fault | |||
exit(myExitCode); // description and exit with our code. | |||
} | |||
} | |||
const string Description() const { return myDescription; } // You can ask for my Description. | |||
const std::string Description() const { return myDescription; } // You can ask for my Description. | |||
const int ExitCode() const { return myExitCode; } // You can ask for my ExitCode. | |||
}; | |||
class RuntimeCheck : public runtime_error { // Throw if this check fails. | |||
class RuntimeCheck : public std::runtime_error { // Throw if this check fails. | |||
public: | |||
RuntimeCheck(const string& Text) : runtime_error(Text) {} // Construct me with a description. | |||
RuntimeCheck(const std::string& Text) : std::runtime_error(Text) {} // Construct me with a description. | |||
void operator()(bool X) const { // Apply me like assert(exp) | |||
if(false == X) { // If the expression is false then we | |||
@@ -129,11 +129,11 @@ class RuntimeCheck : public runtime_error { | |||
} | |||
}; | |||
class RuntimeFault : public runtime_error { // Throw if we find this fault. | |||
class RuntimeFault : public std::runtime_error { // Throw if we find this fault. | |||
public: | |||
RuntimeFault(const string& Text) : runtime_error(Text) {} // Construct me with a description. | |||
RuntimeFault(const std::string& Text) : std::runtime_error(Text) {} // Construct me with a description. | |||
void operator()(bool X) const { // Apply me like assert(exp) | |||
if(true == X) { // If the expression is true then we | |||
@@ -142,11 +142,11 @@ class RuntimeFault : public runtime_error { | |||
} | |||
}; | |||
class LogicCheck : public logic_error { // Throw if this check fails. | |||
class LogicCheck : public std::logic_error { // Throw if this check fails. | |||
public: | |||
LogicCheck(const string& Text) : logic_error(Text) {} // Construct me with a description. | |||
LogicCheck(const std::string& Text) : std::logic_error(Text) {} // Construct me with a description. | |||
void operator()(bool X) const { // Apply me like assert(exp) | |||
if(false == X) { // If the expression is false then we | |||
@@ -155,11 +155,11 @@ class LogicCheck : public logic_error { | |||
} | |||
}; | |||
class LogicFault : public logic_error { // Throw if we find this fault. | |||
class LogicFault : public std::logic_error { // Throw if we find this fault. | |||
public: | |||
LogicFault(const string& Text) : logic_error(Text) {} // Construct me with a description. | |||
LogicFault(const std::string& Text) : std::logic_error(Text) {} // Construct me with a description. | |||
void operator()(bool X) const { // Apply me like assert(exp) | |||
if(true == X) { // If the expression is true then we | |||
@@ -168,6 +168,8 @@ class LogicFault : public logic_error { | |||
} | |||
}; | |||
} // namespace CodeDweller. | |||
#endif | |||
// End Of Include MNR_faults Once Only ========================================= |
@@ -7,8 +7,6 @@ | |||
#include <set> | |||
using namespace std; | |||
/** The Histogram class is managed set of HistogramRecords. | |||
*** We play some naughty tricks with pointers to break the rules and | |||
*** directly manipulate the counts of HistogramRecords stored in the | |||
@@ -18,6 +16,8 @@ using namespace std; | |||
*** ordered by key. | |||
**/ | |||
namespace CodeDweller { | |||
class HistogramRecord { // A record to assocate a key and count. | |||
public: | |||
int Key; // Here is the key. | |||
@@ -30,7 +30,7 @@ class HistogramRecord { | |||
} | |||
}; | |||
class Histogram : public set<HistogramRecord> { // A Histogram is a set of HistogramRecords | |||
class Histogram : public std::set<HistogramRecord> { // A Histogram is a set of HistogramRecords | |||
private: // and a private hit counter... | |||
int HitCount; | |||
public: | |||
@@ -39,7 +39,7 @@ class Histogram : public set<HistogramRecord> { | |||
int hit(const int EventKey, const int Adjustment = 1) { // hit() method increments a specific count. | |||
HistogramRecord E(EventKey); // First, make a record for the event key. | |||
insert(E); // Insert the new record (if it's not there). | |||
set<HistogramRecord>::iterator iE = // Find either the pre-existing or the new | |||
std::set<HistogramRecord>::iterator iE = // Find either the pre-existing or the new | |||
find(E); // record for this key. | |||
int* C; // Play naughty pointer games to access | |||
C = const_cast<int*>(&((*iE).Count)); // the Count for this record inside the | |||
@@ -56,5 +56,7 @@ class Histogram : public set<HistogramRecord> { | |||
} | |||
}; | |||
} // namespace CodeDweller. | |||
#endif | |||
@@ -16,7 +16,9 @@ | |||
// Using new optimized chaos driver for uniformity experiments. | |||
// Important in this experiment is proof of highest possible entropy. | |||
#include "mangler.hpp" | |||
#include "CodeDweller/mangler.hpp" | |||
namespace CodeDweller { | |||
unsigned char MANGLER::ChaosDriver(void) { // Return the current | |||
return Fill[Fill[Position]^Fill[Position^0xff]]; // chaos engine output | |||
@@ -103,4 +105,4 @@ MANGLER::MANGLER(void) : Position(0) { // The default constructor sets | |||
Fill[c]=(unsigned char) c; // value and Position to 0. | |||
} | |||
} |
@@ -11,6 +11,8 @@ | |||
#ifndef _MANGLER_ | |||
#define _MANGLER_ | |||
namespace CodeDweller { | |||
class MANGLER { | |||
private: | |||
@@ -30,5 +32,7 @@ class MANGLER { | |||
MANGLER(void); // Default. | |||
}; | |||
} | |||
#endif | |||
@@ -4,6 +4,8 @@ | |||
#include "onetimepad.hpp" | |||
#include "timing.hpp" | |||
namespace CodeDweller { | |||
/* | |||
class OneTimePad { // One Time Pad generator. | |||
private: | |||
@@ -155,3 +157,4 @@ OneTimePad::OneTimePad() { | |||
} // initial Mangler state. | |||
} // The OneTimePad object is ready. | |||
} |
@@ -16,9 +16,9 @@ | |||
#include <vector> | |||
#include "mangler.hpp" | |||
using namespace std; | |||
namespace CodeDweller { | |||
typedef vector<unsigned char> PadBuffer; | |||
typedef std::vector<unsigned char> PadBuffer; | |||
class OneTimePad { // One Time Pad generator. | |||
private: | |||
@@ -47,4 +47,6 @@ class OneTimePad { | |||
}; | |||
} | |||
#endif |
@@ -82,8 +82,8 @@ extern ThreadManager Threads; | |||
class ThreadState { // Thread State Object. | |||
public: | |||
const string Name; // Text name of thread descriptor. | |||
ThreadState(string N) : Name(N) {} // Constructor requires text name. | |||
const std::string Name; // Text name of thread descriptor. | |||
ThreadState(std::string N) : Name(N) {} // Constructor requires text name. | |||
}; | |||
// ThreadType objects are constant static objects defined for each Thread class | |||
@@ -91,8 +91,8 @@ class ThreadState { | |||
class ThreadType { | |||
public: | |||
const string Name; | |||
ThreadType(string N) : Name(N) {} | |||
const std::string Name; | |||
ThreadType(std::string N) : Name(N) {} | |||
}; | |||
class Thread; // There is such thing as a Thread. | |||
@@ -102,10 +102,10 @@ class ThreadStatusRecord { | |||
Thread* Pointer; // A pointer to the thread. | |||
ThreadType* Type; // A descriptor of it's type. | |||
ThreadState* State; // A descriptor of it's state. | |||
string Name; // Name of the thread if any. | |||
std::string Name; // Name of the thread if any. | |||
bool isRunning; // True if the thread is running. | |||
bool isBad; // True if the thread is bad. | |||
string Fault; // Bad Thread's Fault if any. | |||
std::string Fault; // Bad Thread's Fault if any. | |||
public: | |||
ThreadStatusRecord( // Initialize all items. | |||
@@ -114,8 +114,8 @@ class ThreadStatusRecord { | |||
ThreadState& S, | |||
bool R, | |||
bool B, | |||
string F, | |||
string N | |||
std::string F, | |||
std::string N | |||
) : | |||
Pointer(P), | |||
Type(&T), | |||
@@ -148,11 +148,11 @@ class ThreadStatusRecord { | |||
const ThreadState& getState() { return *State; } | |||
bool getRunning() { return isRunning; } | |||
bool getBad() { return isBad; } | |||
string getFault() { return Fault; } | |||
string getName() { return Name; } | |||
std::string getFault() { return Fault; } | |||
std::string getName() { return Name; } | |||
}; | |||
typedef vector<ThreadStatusRecord> ThreadStatusReport; // Status report type. | |||
typedef std::vector<ThreadStatusRecord> ThreadStatusReport; // Status report type. | |||
// End ThreadDescriptor | |||
//////////////////////////////////////////////////////////////////////////////// | |||
@@ -218,18 +218,18 @@ class Thread { | |||
protected: | |||
const ThreadType& MyThreadType; // Identify thread type. | |||
const string MyThreadName; // Name string of this instance. | |||
const std::string MyThreadName; // Name string of this instance. | |||
thread_primative MyThread; // Abstracted thread. | |||
bool RunningFlag; // True when thread is in myTask() | |||
bool BadFlag; // True when myTask() throws! | |||
string BadWhat; // Bad exception what() if any. | |||
std::string BadWhat; // Bad exception what() if any. | |||
void CurrentThreadState(const ThreadState& TS); // Set thread state. | |||
public: | |||
Thread(); // Constructor (just in case) | |||
Thread(const ThreadType& T, string N); // Construct with specific Type/Name | |||
Thread(const ThreadType& T, std::string N); // Construct with specific Type/Name | |||
virtual ~Thread(); // Destructor (just in case) | |||
void run(); // Method to launch this thread. | |||
@@ -242,9 +242,9 @@ class Thread { | |||
bool isRunning(); // Return the Running flag state. | |||
bool isBad(); // Return the Bad flag state. | |||
const string MyFault(); // Return exception Bad fault if any. | |||
const std::string MyFault(); // Return exception Bad fault if any. | |||
const string MyName() const; // The thread's name. | |||
const std::string MyName() const; // The thread's name. | |||
const ThreadType& MyType(); // Thread type for this thread. | |||
const ThreadState& MyState(); // Returns the current thread state. | |||
const ThreadState& CurrentThreadState(); // Returns the current thread state. | |||
@@ -406,7 +406,7 @@ class ThreadManager { | |||
private: | |||
Mutex MyMutex; // Protect our data with this. | |||
set<Thread*> KnownThreads; // Keep track of all threads. | |||
std::set<Thread*> KnownThreads; // Keep track of all threads. | |||
void rememberThread(Thread* T); // Threads register themselves. | |||
void forgetThread(Thread* T); // Threads remove themselves. | |||
@@ -451,7 +451,7 @@ class ProductionQueue { | |||
Mutex myMutex; // Contains a mutex and | |||
volatile unsigned int LatestSize; // a volatile (blinking light) size | |||
ProductionGateway myGateway; // integrated with a production | |||
queue<T> myQueue; // gateway and a queue. | |||
std::queue<T> myQueue; // gateway and a queue. | |||
public: | |||
ProductionQueue() : LatestSize(0) {} // The size always starts at zero. |