Remove "using namespace std" from these source files, and fix the usage of

string, cout, etc. accordingly, to match both our coding convention (from
the wiki) and the typical C++ ruleset of never using "using namespace".
This commit is contained in:
dgotwisner 2014-03-30 19:26:54 +02:00 committed by Michael Iedema
parent 00294a9fbd
commit b8ca812fde
7 changed files with 74 additions and 89 deletions

View File

@ -32,8 +32,6 @@
#include <cstdlib>
#include <string.h>
using namespace std;
// We must have a gConfig now to include BitVector.
#include "Configuration.h"
ConfigurationTable gConfig;
@ -42,49 +40,49 @@ ConfigurationTable gConfig;
void origTest()
{
BitVector v0("0000111100111100101011110000");
cout << v0 << endl;
std::cout << v0 << std::endl;
// (pat) The conversion from a string was inserting garbage into the result BitVector.
// Fixed now so only 0 or 1 are inserted, but lets check:
for (char *cp = v0.begin(); cp < v0.end(); cp++) cout << (int)*cp<<" ";
cout << endl;
for (char *cp = v0.begin(); cp < v0.end(); cp++) std::cout << (int)*cp<<" ";
std::cout << std::endl;
BitVector v1(v0);
v1.LSB8MSB();
cout <<v1 << " (byte swapped)" << endl;
std::cout <<v1 << " (byte swapped)" << std::endl;
// Test operator==
assert(v1 == v1);
cout <<"v0="<<v0 <<endl;
cout <<"v1="<<v1 <<endl;
std::cout <<"v0="<<v0 <<std::endl;
std::cout <<"v1="<<v1 <<std::endl;
assert(!(v0 == v1));
BitVector v5("000011110000");
int r1 = v5.peekField(0,8);
int r2 = v5.peekField(4,4);
int r3 = v5.peekField(4,8);
cout << r1 << ' ' << r2 << ' ' << r3 << endl;
cout << v5 << endl;
std::cout << r1 << ' ' << r2 << ' ' << r3 << std::endl;
std::cout << v5 << std::endl;
v5.fillField(0,0xa,4);
int r4 = v5.peekField(0,8);
cout << v5 << endl;
cout << r4 << endl;
std::cout << v5 << std::endl;
std::cout << r4 << std::endl;
v5.reverse8();
cout << v5 << endl;
std::cout << v5 << std::endl;
unsigned char ts[9] = "abcdefgh";
BitVector tp(70);
cout << "ts=" << ts << endl;
std::cout << "ts=" << ts << std::endl;
tp.unpack(ts);
cout << "tp=" << tp << endl;
std::cout << "tp=" << tp << std::endl;
tp.pack(ts);
cout << "ts=" << ts << endl;
std::cout << "ts=" << ts << std::endl;
BitVector v6("010101");
BitVector v7(3);
unsigned punk[3] = {1,2,5};
v6.copyPunctured(v7, punk, 3);
cout << "v7=" << v7 << endl;
std::cout << "v7=" << v7 << std::endl;
}
@ -96,20 +94,20 @@ void foo(TestVector a)
}
void anotherTest()
{
cout << "START BitVector anotherTest" << endl;
std::cout << "START BitVector anotherTest" << std::endl;
TestVector v0("0000111100111100101011110000");
TestVector atest = v0.head(3);
cout << atest << endl;
cout << "Calling head" << endl;
cout << v0.head(3) << endl;
cout << "Passing BitVector" << endl;
std::cout << atest << std::endl;
std::cout << "Calling head" << std::endl;
std::cout << v0.head(3) << std::endl;
std::cout << "Passing BitVector" << std::endl;
// This calls Vector const copy constructor.
// That is because the implicitly declared copy constructor for BitVector is of the form (BitVector const&)
foo(v0);
const TestVector ctest("0000");
cout << ctest.cloneSegment(0,2) << endl;
cout << "after"<<endl;
cout << "FINISH anotherTest" << endl;
std::cout << ctest.cloneSegment(0,2) << std::endl;
std::cout << "after"<<std::endl;
std::cout << "FINISH anotherTest" << std::endl;
}
BitVector randomBitVector(int n)

View File

@ -30,14 +30,12 @@
#include <iostream>
#include <string>
using namespace std;
ConfigurationKeyMap getConfigurationKeys();
ConfigurationTable gConfig("exampleconfig.db","test", getConfigurationKeys());
void purgeConfig(void*,int,char const*, char const*, sqlite3_int64)
{
//cout << "update hook" << endl;
//std::cout << "update hook" << std::endl;
gConfig.purge();
}
@ -54,29 +52,29 @@ int main(int argc, char *argv[])
}
for (int i=0; i<5; i++) {
cout << "table[" << keys[i] << "]=" << gConfig.getStr(keys[i]) << endl;
cout << "table[" << keys[i] << "]=" << gConfig.getNum(keys[i]) << endl;
std::cout << "table[" << keys[i] << "]=" << gConfig.getStr(keys[i]) << std::endl;
std::cout << "table[" << keys[i] << "]=" << gConfig.getNum(keys[i]) << std::endl;
}
for (int i=0; i<5; i++) {
cout << "defined table[" << keys[i] << "]=" << gConfig.defines(keys[i]) << endl;
std::cout << "defined table[" << keys[i] << "]=" << gConfig.defines(keys[i]) << std::endl;
}
gConfig.set("key5","100 200 300 400 ");
std::vector<unsigned> vect = gConfig.getVector("key5");
cout << "vect length " << vect.size() << ": ";
for (unsigned i=0; i<vect.size(); i++) cout << " " << vect[i];
cout << endl;
std::vector<string> svect = gConfig.getVectorOfStrings("key5");
cout << "vect length " << svect.size() << ": ";
for (unsigned i=0; i<svect.size(); i++) cout << " " << svect[i] << ":";
cout << endl;
std::cout << "vect length " << vect.size() << ": ";
for (unsigned i=0; i<vect.size(); i++) std::cout << " " << vect[i];
std::cout << std::endl;
std::vector<std::string> svect = gConfig.getVectorOfStrings("key5");
std::cout << "vect length " << svect.size() << ": ";
for (unsigned i=0; i<svect.size(); i++) std::cout << " " << svect[i] << ":";
std::cout << std::endl;
cout << "bool " << gConfig.getBool("booltest") << endl;
std::cout << "bool " << gConfig.getBool("booltest") << std::endl;
gConfig.set("booltest",1);
cout << "bool " << gConfig.getBool("booltest") << endl;
std::cout << "bool " << gConfig.getBool("booltest") << std::endl;
gConfig.set("booltest",0);
cout << "bool " << gConfig.getBool("booltest") << endl;
std::cout << "bool " << gConfig.getBool("booltest") << std::endl;
gConfig.getStr("newstring");
gConfig.getNum("numnumber");
@ -84,26 +82,26 @@ int main(int argc, char *argv[])
SimpleKeyValue pairs;
pairs.addItems(" a=1 b=34 dd=143 ");
cout<< pairs.get("a") << endl;
cout<< pairs.get("b") << endl;
cout<< pairs.get("dd") << endl;
std::cout<< pairs.get("a") << std::endl;
std::cout<< pairs.get("b") << std::endl;
std::cout<< pairs.get("dd") << std::endl;
gConfig.set("fkey","123.456");
float fval = gConfig.getFloat("fkey");
cout << "fkey " << fval << endl;
std::cout << "fkey " << fval << std::endl;
cout << "search fkey:" << endl;
gConfig.find("fkey",cout);
cout << "search fkey:" << endl;
gConfig.find("fkey",cout);
std::cout << "search fkey:" << std::endl;
gConfig.find("fkey",std::cout);
std::cout << "search fkey:" << std::endl;
gConfig.find("fkey",std::cout);
gConfig.remove("fkey");
cout << "search fkey:" << endl;
gConfig.find("fkey",cout);
std::cout << "search fkey:" << std::endl;
gConfig.find("fkey",std::cout);
try {
gConfig.getNum("supposedtoabort");
} catch (ConfigurationTableKeyNotFound) {
cout << "ConfigurationTableKeyNotFound exception successfully caught." << endl;
std::cout << "ConfigurationTableKeyNotFound exception successfully caught." << std::endl;
}
}

View File

@ -31,8 +31,6 @@
#include "Configuration.h"
ConfigurationTable gConfig;
using namespace std;
InterthreadQueue<int> gQ;
InterthreadMap<int,int> gMap;

View File

@ -28,8 +28,6 @@
#include "Regexp.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
@ -40,9 +38,9 @@ int main(int argc, char *argv[])
const char text1[] = "dburgess@jcis.net test message";
const char text2[] = "no address text message";
cout << email.match(text1) << " " << text1 << endl;
cout << email.match(text2) << " " << text2 << endl;
std::cout << email.match(text1) << " " << text1 << std::endl;
std::cout << email.match(text2) << " " << text2 << std::endl;
cout << simple.match(text1) << " " << text1 << endl;
cout << simple.match(text2) << " " << text2 << endl;
std::cout << simple.match(text1) << " " << text1 << std::endl;
std::cout << simple.match(text2) << " " << text2 << std::endl;
}

View File

@ -29,17 +29,15 @@
#include "Timeval.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Timeval then(10000);
cout << then.elapsed() << endl;
std::cout << then.elapsed() << std::endl;
while (!then.passed()) {
cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
std::cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << std::endl;
usleep(500000);
}
cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
std::cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << std::endl;
}

View File

@ -4,14 +4,11 @@
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string test = string("Testing: !@#$%^&*() " __DATE__ " " __TIME__);
cout << test << endl;
cout << URLEncode(test) << endl;
std::string test = std::string("Testing: !@#$%^&*() " __DATE__ " " __TIME__);
std::cout << test << std::endl;
std::cout << URLEncode(test) << std::endl;
}

View File

@ -32,8 +32,6 @@
#include "Configuration.h"
ConfigurationTable gConfig;
using namespace std;
typedef Vector<int> TestVector;
int barfo;
void foo(TestVector a)
@ -42,16 +40,16 @@ void foo(TestVector a)
}
void anotherTest()
{
cout << "START Vector anotherTest" << endl;
std::cout << "START Vector anotherTest" << std::endl;
TestVector v0(10);
TestVector atest = v0.head(3);
cout << atest << endl;
cout << "calling head" << endl;
cout << v0.head(3) << endl;
cout << "Passing Vector" << endl;
std::cout << atest << std::endl;
std::cout << "calling head" << std::endl;
std::cout << v0.head(3) << std::endl;
std::cout << "Passing Vector" << std::endl;
// This calls the Vector non-const copy constructor
foo(v0);
cout << "FINISH anotherTest" << endl;
std::cout << "FINISH anotherTest" << std::endl;
}
int main(int argc, char *argv[])
@ -62,26 +60,26 @@ int main(int argc, char *argv[])
TestVector test2(5);
for (int i=0; i<5; i++) test2[i]=10+i;
cout << test1 << endl;
cout << test2 << endl;
std::cout << test1 << std::endl;
std::cout << test2 << std::endl;
{
TestVector testC(test1,test2);
cout << testC << endl;
std::cout << testC << std::endl;
TestVector foo = testC.head(3);
//cout << testC.head(3) << endl;
cout << testC.tail(3) << endl;
//std::cout << testC.head(3) << std::endl;
std::cout << testC.tail(3) << std::endl;
testC.fill(8);
cout << testC << endl;
std::cout << testC << std::endl;
test1.copyToSegment(testC,3);
cout << testC << endl;
std::cout << testC << std::endl;
TestVector testD(testC.segment(4,3));
cout << testD << endl;
std::cout << testD << std::endl;
testD.fill(9);
cout << testC << endl;
cout << testD << endl;
std::cout << testC << std::endl;
std::cout << testD << std::endl;
}
return 0;