diff --git a/BitVector.cpp b/BitVector.cpp index c54681e..a36ab7b 100644 --- a/BitVector.cpp +++ b/BitVector.cpp @@ -32,6 +32,8 @@ #include #include +using namespace std; + BitVector::BitVector(const char *valString) @@ -236,7 +238,7 @@ void BitVector::unmap(const unsigned *map, size_t mapSize, BitVector& dest) cons -std::ostream& operator<<(std::ostream& os, const BitVector& hv) +ostream& operator<<(ostream& os, const BitVector& hv) { for (size_t i=0; i> (8-rem),rem); } -void BitVector::hex(std::ostream& os) const +void BitVector::hex(ostream& os) const { os << std::hex; unsigned digits = size()/4; diff --git a/BitVectorTest.cpp b/BitVectorTest.cpp index 5ae6bec..63ab10b 100644 --- a/BitVectorTest.cpp +++ b/BitVectorTest.cpp @@ -32,6 +32,8 @@ #include #include +using namespace std; + // We must have a gConfig now to include BitVector. #include "Configuration.h" ConfigurationTable gConfig; @@ -40,49 +42,49 @@ ConfigurationTable gConfig; void origTest() { BitVector v0("0000111100111100101011110000"); - std::cout << v0 << std::endl; + cout << v0 << 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++) std::cout << (int)*cp<<" "; - std::cout << std::endl; + for (char *cp = v0.begin(); cp < v0.end(); cp++) cout << (int)*cp<<" "; + cout << endl; BitVector v1(v0); v1.LSB8MSB(); - std::cout <first; + string name = it->first; ConfigurationKey key = it->second; if (name != key.getName()) { LOG(ALERT) << "SQL database is corrupt at name:"<getStr(name); + string defaultValue= key.getDefaultValue(); + string value = this->getStr(name); if (value != defaultValue) { LOG(INFO) << "Config Variable"<second.getDescription(); + const string description = mp->second.getDescription(); // Try to use a quote that will work: if the description contains ' quote with " else '. // This is not perfect because these quotes could themselves be quoted. - const char * quote = std::string::npos != description.find('\'') ? "\"" : "'"; + const char * quote = string::npos != description.find('\'') ? "\"" : "'"; ss << quote; if (mp->second.getType() == ConfigurationKey::BOOLEAN) { ss << "1=enabled, 0=disabled - "; @@ -256,28 +258,28 @@ std::string ConfigurationTable::getDefaultSQL(const std::string& program, const ss << " Static."; } ss << quote; - ss << ");" << std::endl; + ss << ");" << endl; mp++; } - ss << "COMMIT;" << std::endl; - ss << std::endl; + ss << "COMMIT;" << endl; + ss << endl; return ss.str(); } -std::string ConfigurationTable::getTeX(const std::string& program, const std::string& version) +string ConfigurationTable::getTeX(const std::string& program, const std::string& version) { - std::stringstream ss; + stringstream ss; ConfigurationKeyMap::iterator mp; - ss << "% START AUTO-GENERATED CONTENT" << std::endl; - ss << "% -- these sections were generated using: " << program << " --gentex" << std::endl; - ss << "% -- binary version: " << version << std::endl; + ss << "% START AUTO-GENERATED CONTENT" << endl; + ss << "% -- these sections were generated using: " << program << " --gentex" << endl; + ss << "% -- binary version: " << version << endl; - ss << "\\section{Customer Site Parameters}" << std::endl; - ss << "These parameters must be changed to fit your site." << std::endl; - ss << "\\begin{itemize}" << std::endl; + ss << "\\section{Customer Site Parameters}" << endl; + ss << "These parameters must be changed to fit your site." << endl; + ss << "\\begin{itemize}" << endl; mp = mSchema.begin(); while (mp != mSchema.end()) { if (mp->second.getVisibility() == ConfigurationKey::CUSTOMERSITE) { @@ -286,16 +288,16 @@ std::string ConfigurationTable::getTeX(const std::string& program, const std::st ss << mp->first << "} -- "; // description ss << mp->second.getDescription(); - ss << std::endl; + ss << endl; } mp++; } - ss << "\\end{itemize}" << std::endl; - ss << std::endl; + ss << "\\end{itemize}" << endl; + ss << endl; - ss << "\\section{Customer Tuneable Parameters}" << std::endl; - ss << "These parameters can be changed to optimize your site." << std::endl; - ss << "\\begin{itemize}" << std::endl; + ss << "\\section{Customer Tuneable Parameters}" << endl; + ss << "These parameters can be changed to optimize your site." << endl; + ss << "\\begin{itemize}" << endl; mp = mSchema.begin(); while (mp != mSchema.end()) { if (mp->second.getVisibility() != ConfigurationKey::CUSTOMERSITE && @@ -309,16 +311,16 @@ std::string ConfigurationTable::getTeX(const std::string& program, const std::st ss << mp->first << "} -- "; // description ss << mp->second.getDescription(); - ss << std::endl; + ss << endl; } mp++; } - ss << "\\end{itemize}" << std::endl; - ss << std::endl; + ss << "\\end{itemize}" << endl; + ss << endl; - ss << "\\section{Developer/Factory Parameters}" << std::endl; - ss << "These parameters should only be changed by when developing new code." << std::endl; - ss << "\\begin{itemize}" << std::endl; + ss << "\\section{Developer/Factory Parameters}" << endl; + ss << "These parameters should only be changed by when developing new code." << endl; + ss << "\\begin{itemize}" << endl; mp = mSchema.begin(); while (mp != mSchema.end()) { if (mp->second.getVisibility() == ConfigurationKey::FACTORY || @@ -328,19 +330,19 @@ std::string ConfigurationTable::getTeX(const std::string& program, const std::st ss << mp->first << "} -- "; // description ss << mp->second.getDescription(); - ss << std::endl; + ss << endl; } mp++; } - ss << "\\end{itemize}" << std::endl; - ss << "% END AUTO-GENERATED CONTENT" << std::endl; - ss << std::endl; + ss << "\\end{itemize}" << endl; + ss << "% END AUTO-GENERATED CONTENT" << endl; + ss << endl; - std::string tmp = Utils::replaceAll(ss.str(), "^", "\\^"); + string tmp = Utils::replaceAll(ss.str(), "^", "\\^"); return Utils::replaceAll(tmp, "_", "\\_"); } -bool ConfigurationTable::defines(const std::string& key) +bool ConfigurationTable::defines(const string& key) { try { ScopedLock lock(mLock); @@ -637,7 +639,7 @@ ConfigurationKeyMap ConfigurationTable::getSimilarKeys(const std::string& snippe return tmp; } -const ConfigurationRecord& ConfigurationTable::lookup(const std::string& key) +const ConfigurationRecord& ConfigurationTable::lookup(const string& key) { assert(mDB); checkCacheAge(); @@ -678,7 +680,7 @@ const ConfigurationRecord& ConfigurationTable::lookup(const std::string& key) -bool ConfigurationTable::isStatic(const std::string& key) +bool ConfigurationTable::isStatic(const string& key) { if (keyDefinedInSchema(key)) { return mSchema[key].isStatic(); @@ -690,7 +692,7 @@ bool ConfigurationTable::isStatic(const std::string& key) -std::string ConfigurationTable::getStr(const std::string& key) +string ConfigurationTable::getStr(const string& key) { // We need the lock because rec is a reference into the cache. try { @@ -704,7 +706,7 @@ std::string ConfigurationTable::getStr(const std::string& key) } -bool ConfigurationTable::getBool(const std::string& key) +bool ConfigurationTable::getBool(const string& key) { try { return getNum(key) != 0; @@ -716,7 +718,7 @@ bool ConfigurationTable::getBool(const std::string& key) } -long ConfigurationTable::getNum(const std::string& key) +long ConfigurationTable::getNum(const string& key) { // We need the lock because rec is a reference into the cache. try { @@ -730,7 +732,7 @@ long ConfigurationTable::getNum(const std::string& key) } -float ConfigurationTable::getFloat(const std::string& key) +float ConfigurationTable::getFloat(const string& key) { try { ScopedLock lock(mLock); @@ -742,7 +744,7 @@ float ConfigurationTable::getFloat(const std::string& key) } } -std::vector ConfigurationTable::getVectorOfStrings(const std::string& key) +std::vector ConfigurationTable::getVectorOfStrings(const string& key) { // Look up the string. char *line=NULL; @@ -760,7 +762,7 @@ std::vector ConfigurationTable::getVectorOfStrings(const std::strin char *lp = line; // Parse the string. - std::vector retVal; + std::vector retVal; while (lp) { while (*lp==' ') lp++; if (*lp == '\0') break; @@ -773,7 +775,7 @@ std::vector ConfigurationTable::getVectorOfStrings(const std::strin } -std::vector ConfigurationTable::getVector(const std::string& key) +std::vector ConfigurationTable::getVector(const string& key) { // Look up the string. char *line=NULL; @@ -804,7 +806,7 @@ std::vector ConfigurationTable::getVector(const std::string& key) } -bool ConfigurationTable::remove(const std::string& key) +bool ConfigurationTable::remove(const string& key) { assert(mDB); @@ -813,16 +815,16 @@ bool ConfigurationTable::remove(const std::string& key) ConfigurationMap::iterator where = mCache.find(key); if (where!=mCache.end()) mCache.erase(where); // Really remove it. - std::string cmd = "DELETE FROM CONFIG WHERE KEYSTRING=='"+key+"'"; + string cmd = "DELETE FROM CONFIG WHERE KEYSTRING=='"+key+"'"; return sqlite3_command(mDB,cmd.c_str()); } -void ConfigurationTable::find(const std::string& pat, std::ostream& os) const +void ConfigurationTable::find(const string& pat, ostream& os) const { // Prepare the statement. - std::string cmd = "SELECT KEYSTRING,VALUESTRING FROM CONFIG WHERE KEYSTRING LIKE \"%" + pat + "%\""; + string cmd = "SELECT KEYSTRING,VALUESTRING FROM CONFIG WHERE KEYSTRING LIKE \"%" + pat + "%\""; sqlite3_stmt *stmt; if (sqlite3_prepare_statement(mDB,&stmt,cmd.c_str())) return; // Read the result. @@ -834,8 +836,8 @@ void ConfigurationTable::find(const std::string& pat, std::ostream& os) const if (value) { len = strlen(value); } - if (len && value) os << value << std::endl; - else os << "(disabled)" << std::endl; + if (len && value) os << value << endl; + else os << "(disabled)" << endl; src = sqlite3_run_query(mDB,stmt); } sqlite3_finalize(stmt); @@ -847,7 +849,7 @@ ConfigurationRecordMap ConfigurationTable::getAllPairs() const ConfigurationRecordMap tmp; // Prepare the statement. - std::string cmd = "SELECT KEYSTRING,VALUESTRING FROM CONFIG"; + string cmd = "SELECT KEYSTRING,VALUESTRING FROM CONFIG"; sqlite3_stmt *stmt; if (sqlite3_prepare_statement(mDB,&stmt,cmd.c_str())) return tmp; // Read the result. @@ -856,10 +858,10 @@ ConfigurationRecordMap ConfigurationTable::getAllPairs() const const char* key = (const char*)sqlite3_column_text(stmt,0); const char* value = (const char*)sqlite3_column_text(stmt,1); if (key && value) { - std::string skey(key); + string skey(key); tmp[skey] = ConfigurationRecord(skey,value); } else if (key && !value) { - std::string skey(key); + string skey(key); tmp[skey] = ConfigurationRecord(skey,false); } src = sqlite3_run_query(mDB,stmt); @@ -869,11 +871,11 @@ ConfigurationRecordMap ConfigurationTable::getAllPairs() const return tmp; } -bool ConfigurationTable::set(const std::string& key, const std::string& value) +bool ConfigurationTable::set(const string& key, const string& value) { assert(mDB); ScopedLock lock(mLock); - std::string cmd; + string cmd; if (keyDefinedInSchema(key)) { cmd = "INSERT OR REPLACE INTO CONFIG (KEYSTRING,VALUESTRING,OPTIONAL,COMMENTS) VALUES (\"" + key + "\",\"" + value + "\",1,\'" + mSchema[key].getDescription() + "\')"; } else { @@ -886,7 +888,7 @@ bool ConfigurationTable::set(const std::string& key, const std::string& value) return success; } -bool ConfigurationTable::set(const std::string& key, long value) +bool ConfigurationTable::set(const string& key, long value) { char buffer[30]; sprintf(buffer,"%ld",value); @@ -931,14 +933,14 @@ void ConfigurationTable::setUpdateHook(void(*func)(void *,int ,char const *,char } -void ConfigurationTable::setCrossCheckHook(std::vector (*wCrossCheck)(const std::string&)) +void ConfigurationTable::setCrossCheckHook(vector (*wCrossCheck)(const string&)) { mCrossCheck = wCrossCheck; } -std::vector ConfigurationTable::crossCheck(const std::string& key) { - std::vector ret; +vector ConfigurationTable::crossCheck(const string& key) { + vector ret; if (mCrossCheck != NULL) { ret = mCrossCheck(key); @@ -1152,7 +1154,7 @@ const std::string ConfigurationKey::typeToString(const ConfigurationKey::Type& t return ret; } -void ConfigurationKey::printKey(const ConfigurationKey &key, const std::string& currentValue, std::ostream& os) { +void ConfigurationKey::printKey(const ConfigurationKey &key, const std::string& currentValue, ostream& os) { os << key.getName() << " "; if (!currentValue.length()) { os << "(disabled)"; @@ -1162,10 +1164,10 @@ void ConfigurationKey::printKey(const ConfigurationKey &key, const std::string& if (currentValue.compare(key.getDefaultValue()) == 0) { os << " [default]"; } - os << std::endl; + os << endl; } -void ConfigurationKey::printDescription(const ConfigurationKey &key, std::ostream& os) { +void ConfigurationKey::printDescription(const ConfigurationKey &key, ostream& os) { std::string tmp; unsigned scope; diff --git a/ConfigurationTest.cpp b/ConfigurationTest.cpp index 5e22161..3d8014b 100644 --- a/ConfigurationTest.cpp +++ b/ConfigurationTest.cpp @@ -30,12 +30,14 @@ #include #include +using namespace std; + ConfigurationKeyMap getConfigurationKeys(); ConfigurationTable gConfig("exampleconfig.db","test", getConfigurationKeys()); void purgeConfig(void*,int,char const*, char const*, sqlite3_int64) { - //std::cout << "update hook" << std::endl; + //cout << "update hook" << endl; gConfig.purge(); } @@ -52,29 +54,29 @@ int main(int argc, char *argv[]) } for (int i=0; i<5; i++) { - std::cout << "table[" << keys[i] << "]=" << gConfig.getStr(keys[i]) << std::endl; - std::cout << "table[" << keys[i] << "]=" << gConfig.getNum(keys[i]) << std::endl; + cout << "table[" << keys[i] << "]=" << gConfig.getStr(keys[i]) << endl; + cout << "table[" << keys[i] << "]=" << gConfig.getNum(keys[i]) << endl; } for (int i=0; i<5; i++) { - std::cout << "defined table[" << keys[i] << "]=" << gConfig.defines(keys[i]) << std::endl; + cout << "defined table[" << keys[i] << "]=" << gConfig.defines(keys[i]) << endl; } gConfig.set("key5","100 200 300 400 "); std::vector vect = gConfig.getVector("key5"); - std::cout << "vect length " << vect.size() << ": "; - for (unsigned i=0; i svect = gConfig.getVectorOfStrings("key5"); - std::cout << "vect length " << svect.size() << ": "; - for (unsigned i=0; i svect = gConfig.getVectorOfStrings("key5"); + cout << "vect length " << svect.size() << ": "; + for (unsigned i=0; i +using namespace std; + int main(int argc, char **argv) { @@ -36,18 +38,18 @@ int main(int argc, char **argv) F16 c = 2.5 * 1.5; F16 d = c + a; F16 e = 10; - std::cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << std::endl; + cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << endl; a *= 3; b *= 0.3; c *= e; - std::cout << a << ' ' << b << ' ' << c << ' ' << d << std::endl; + cout << a << ' ' << b << ' ' << c << ' ' << d << endl; a /= 3; b /= 0.3; c = d * 0.05; - std::cout << a << ' ' << b << ' ' << c << ' ' << d << std::endl; + cout << a << ' ' << b << ' ' << c << ' ' << d << endl; F16 f = a/d; - std::cout << f << ' ' << f+0.5 << std::endl; + cout << f << ' ' << f+0.5 << endl; } diff --git a/InterthreadTest.cpp b/InterthreadTest.cpp index fb465eb..552c1ee 100644 --- a/InterthreadTest.cpp +++ b/InterthreadTest.cpp @@ -31,6 +31,8 @@ #include "Configuration.h" ConfigurationTable gConfig; +using namespace std; + InterthreadQueue gQ; InterthreadMap gMap; diff --git a/Logger.cpp b/Logger.cpp index c84cc57..03a1059 100644 --- a/Logger.cpp +++ b/Logger.cpp @@ -36,6 +36,8 @@ #include "Threads.h" // pat added +using namespace std; + // Reference to a global config table, used all over the system. extern ConfigurationTable gConfig; @@ -43,8 +45,8 @@ extern ConfigurationTable gConfig; /**@ The global alarms table. */ //@{ Mutex alarmsLock; -std::list alarmsList; -void addAlarm(const std::string&); +list alarmsList; +void addAlarm(const string&); //@} // (pat 3-2014) Note that the logger is used by multiple programs. @@ -73,7 +75,7 @@ Mutex gLogToLock; LogGroup gLogGroup; -int levelStringToInt(const std::string& name) +int levelStringToInt(const string& name) { // Reverse search, since the numerically larger levels are more common. for (int i=numLevels-1; i>=0; i--) { @@ -92,13 +94,13 @@ int levelStringToInt(const std::string& name) } /** Given a string, return the corresponding level name. */ -int lookupLevel(const std::string& key) +int lookupLevel(const string& key) { - std::string val = gConfig.getStr(key); + string val = gConfig.getStr(key); int level = levelStringToInt(val); if (level == -1) { - std::string defaultLevel = gConfig.mSchema["Log.Level"].getDefaultValue(); + string defaultLevel = gConfig.mSchema["Log.Level"].getDefaultValue(); level = levelStringToInt(defaultLevel); _LOG(CRIT) << "undefined logging level (" << key << " = \"" << val << "\") defaulting to \"" << defaultLevel << ".\" Valid levels are: EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO or DEBUG"; gConfig.set(key, defaultLevel); @@ -114,7 +116,7 @@ int getLoggingLevel(const char* filename) if (!filename) return lookupLevel("Log.Level"); // This can afford to be inefficient since it is not called that often. - const std::string keyName = std::string("Log.Level.") + std::string(filename); + const string keyName = string("Log.Level.") + string(filename); if (gConfig.defines(keyName)) return lookupLevel(keyName); return lookupLevel("Log.Level"); } @@ -122,7 +124,7 @@ int getLoggingLevel(const char* filename) //bool gCheckGroupLogLevel(const char *groupname, int loglevel) //{ // // Gag me -// std::string keyName = std::string("Log.Group.") + groupname; +// string keyName = string("Log.Group.") + groupname; // return gConfig.defines(keyName) ? (lookupLevel(gConfig.getStr(keyName)) >= loglevel) : false; //} @@ -133,7 +135,7 @@ int gGetLoggingLevel(const char* filename) // This is called a lot and needs to be efficient. static Mutex sLogCacheLock; - static std::map sLogCache; + static map sLogCache; static unsigned sCacheCount; static const unsigned sCacheRefreshCount = 1000; @@ -149,7 +151,7 @@ int gGetLoggingLevel(const char* filename) sCacheCount=0; } // Is it cached already? - std::map::const_iterator where = sLogCache.find(key); + map::const_iterator where = sLogCache.find(key); sCacheCount++; if (where!=sLogCache.end()) { int retVal = where->second; @@ -162,7 +164,7 @@ int gGetLoggingLevel(const char* filename) sLogCacheLock.unlock(); int level = getLoggingLevel(filename); sLogCacheLock.lock(); - sLogCache.insert(std::pair(key,level)); + sLogCache.insert(pair(key,level)); sLogCacheLock.unlock(); return level; } @@ -172,20 +174,20 @@ int gGetLoggingLevel(const char* filename) // copies the alarm list and returns it. list supposed to be small. -std::list gGetLoggerAlarms() +list gGetLoggerAlarms() { alarmsLock.lock(); - std::list ret; + list ret; // excuse the "complexity", but to use std::copy with a list you need // an insert_iterator - copy technically overwrites, doesn't insert. - std::insert_iterator< std::list > ii(ret, ret.begin()); + insert_iterator< list > ii(ret, ret.begin()); copy(alarmsList.begin(), alarmsList.end(), ii); alarmsLock.unlock(); return ret; } /** Add an alarm to the alarm list. */ -void addAlarm(const std::string& s) +void addAlarm(const string& s) { alarmsLock.lock(); alarmsList.push_back(s); @@ -202,7 +204,7 @@ Log::~Log() // Save alarms in the local list and echo them to stderr. if (mPriority <= LOG_CRIT) { if (sLoggerInited) addAlarm(mStream.str().c_str()); - std::cerr << mStream.str() << std::endl; + cerr << mStream.str() << endl; } // Current logging level was already checked by the macro. // So just log. @@ -244,7 +246,7 @@ Log::Log(const char* name, const char* level, int facility) } -std::ostringstream& Log::get() +ostringstream& Log::get() { assert(mPriority3) { // strlen because a garbage char is getting in sometimes. @@ -371,7 +373,7 @@ static const char *LogGroupPrefix = "Log.Group."; #if UNUSED // Return true if this was a LogGroup config parameter. // These dont have to be fast. -bool LogGroup::setGroup(const std::string groupName, const std::string levelName) +bool LogGroup::setGroup(const string groupName, const string levelName) { const int len = strlen(LogGroupPrefix); if (0 != strncasecmp(groupName.c_str(),LogGroupPrefix,len)) { return false; } @@ -383,13 +385,13 @@ bool LogGroup::setGroup(const std::string groupName, const std::string levelName } //GroupMapType::iterator it = mGroupNameToIndex.find(groupName); - //if (it != std::map::end) { + //if (it != map::end) { // mDebugLevel[it->second] = lookupLevel(levelName); //} return true; } -bool LogGroup::unsetGroup(const std::string groupName) +bool LogGroup::unsetGroup(const string groupName) { const int len = strlen(LogGroupPrefix); if (0 != strncasecmp(groupName.c_str(),LogGroupPrefix,len)) { return false; } @@ -401,7 +403,7 @@ bool LogGroup::unsetGroup(const std::string groupName) } //GroupMapType::iterator it = mGroupNameToIndex.find(groupName); - //if (it != std::map::end) { + //if (it != map::end) { // mDebugLevel[it->second] = lookupLevel(levelName); //} return true; @@ -411,11 +413,11 @@ bool LogGroup::unsetGroup(const std::string groupName) void LogGroup::setAll() { LOG(DEBUG); - std::string prefix = std::string(LogGroupPrefix); + string prefix = string(LogGroupPrefix); for (unsigned g = 0; g < _NumberOfLogGroups; g++) { - std::string param = prefix + mGroupNames[g]; + string param = prefix + mGroupNames[g]; if (gConfig.defines(param)) { - std::string levelName = gConfig.getStr(param); + string levelName = gConfig.getStr(param); LOG(DEBUG) << "Setting "< +using namespace std; + int main(int argc, char *argv[]) { @@ -38,9 +40,9 @@ int main(int argc, char *argv[]) const char text1[] = "dburgess@jcis.net test message"; const char text2[] = "no address text message"; - std::cout << email.match(text1) << " " << text1 << std::endl; - std::cout << email.match(text2) << " " << text2 << std::endl; + cout << email.match(text1) << " " << text1 << endl; + cout << email.match(text2) << " " << text2 << endl; - std::cout << simple.match(text1) << " " << text1 << std::endl; - std::cout << simple.match(text2) << " " << text2 << std::endl; + cout << simple.match(text1) << " " << text1 << endl; + cout << simple.match(text2) << " " << text2 << endl; } diff --git a/Threads.cpp b/Threads.cpp index add97ea..191d518 100644 --- a/Threads.cpp +++ b/Threads.cpp @@ -33,6 +33,8 @@ #include +using namespace std; + int gMutexLogLevel = LOG_INFO; // The mutexes cannot call gConfig or gGetLoggingLevel so we have to get the log level indirectly. @@ -49,13 +51,13 @@ void lockCout() { gStreamLock.lock(); Timeval entryTime; - std::cout << entryTime << " " << pthread_self() << ": "; + cout << entryTime << " " << pthread_self() << ": "; } void unlockCout() { - std::cout << std::dec << std::endl << std::flush; + cout << dec << endl << flush; gStreamLock.unlock(); } @@ -64,12 +66,12 @@ void lockCerr() { gStreamLock.lock(); Timeval entryTime; - std::cerr << entryTime << " " << pthread_self() << ": "; + cerr << entryTime << " " << pthread_self() << ": "; } void unlockCerr() { - std::cerr << std::dec << std::endl << std::flush; + cerr << dec << endl << flush; gStreamLock.unlock(); } @@ -119,9 +121,9 @@ bool Mutex::timedlock(int msecs) // Wait this long in milli-seconds. return ETIMEDOUT != pthread_mutex_timedlock(&mMutex, &timeout); } -std::string Mutex::mutext() const +string Mutex::mutext() const { - std::string result; + string result; result.reserve(100); //result += format("lockid=%u lockcnt=%d",(unsigned)this,mLockCnt); result += format("lockcnt=%d",mLockCnt); diff --git a/Timeval.cpp b/Timeval.cpp index 875c103..642c05a 100644 --- a/Timeval.cpp +++ b/Timeval.cpp @@ -27,6 +27,8 @@ #include "Timeval.h" +using namespace std; + void Timeval::future(unsigned offset) // In msecs { now(); @@ -77,15 +79,15 @@ long Timeval::delta(const Timeval& other) const -std::ostream& operator<<(std::ostream& os, const Timeval& tv) +ostream& operator<<(ostream& os, const Timeval& tv) { - os.setf( std::ios::fixed, std::ios::floatfield ); + os.setf( ios::fixed, ios::floatfield ); os << tv.seconds(); return os; } -std::ostream& operator<<(std::ostream& os, const struct timespec& ts) +ostream& operator<<(ostream& os, const struct timespec& ts) { os << ts.tv_sec << "," << ts.tv_nsec; return os; diff --git a/TimevalTest.cpp b/TimevalTest.cpp index 45ed2d1..b4746f2 100644 --- a/TimevalTest.cpp +++ b/TimevalTest.cpp @@ -29,15 +29,17 @@ #include "Timeval.h" #include +using namespace std; + int main(int argc, char *argv[]) { Timeval then(10000); - std::cout << then.elapsed() << std::endl; + cout << then.elapsed() << endl; while (!then.passed()) { - std::cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << std::endl; + cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl; usleep(500000); } - std::cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << std::endl; + cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl; } diff --git a/URLEncode.cpp b/URLEncode.cpp index d76a33a..cdf38dd 100644 --- a/URLEncode.cpp +++ b/URLEncode.cpp @@ -5,11 +5,13 @@ #include #include +using namespace std; + //based on javascript encodeURIComponent() -std::string URLEncode(const std::string &c) +string URLEncode(const string &c) { static const char *digits = "01234567890ABCDEF"; - std::string retVal=""; + string retVal=""; for (size_t i=0; i +using namespace std; + + int main(int argc, char *argv[]) { - std::string test = std::string("Testing: !@#$%^&*() " __DATE__ " " __TIME__); - std::cout << test << std::endl; - std::cout << URLEncode(test) << std::endl; + string test = string("Testing: !@#$%^&*() " __DATE__ " " __TIME__); + cout << test << endl; + cout << URLEncode(test) << endl; } diff --git a/Utils.cpp b/Utils.cpp index d4f10c0..78d3500 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -26,6 +26,7 @@ #include "MemoryLeak.h" namespace Utils { +using namespace std; // (pat) This definition must be in the .cpp file to anchor the class vtable. RefCntBase::~RefCntBase() { LOG(DEBUG) << typeid(this).name(); } @@ -67,7 +68,7 @@ MemStats::MemStats() memset(mMemName,0,sizeof(mMemName)); } -void MemStats::text(std::ostream &os) +void MemStats::text(ostream &os) { os << "Structs current total:\n"; for (int i = 0; i < mMax; i++) { @@ -77,7 +78,7 @@ void MemStats::text(std::ostream &os) void MemStats::memChkNew(MemoryNames memIndex, const char *id) { - /*std::cout << "new " #type "\n";*/ + /*cout << "new " #type "\n";*/ ScopedLock lock(memChkLock); mMemNow[memIndex]++; mMemTotal[memIndex]++; @@ -87,7 +88,7 @@ void MemStats::memChkNew(MemoryNames memIndex, const char *id) void MemStats::memChkDel(MemoryNames memIndex, const char *id) { ScopedLock lock(memChkLock); - /*std::cout << "del " #type "\n";*/ + /*cout << "del " #type "\n";*/ mMemNow[memIndex]--; if (mMemNow[memIndex] < 0) { LOG(ERR) << "Memory reference count underflow on type "< 5000) { LOG(ERR) << "oversized string in format"; n = 5000; } // We could use vasprintf but we already computed the length... @@ -132,12 +133,12 @@ std::string format(const char *fmt, ...) vsnprintf(buffer,n+1,fmt,ap); va_end(ap); //if (n >= (2000-4)) { strcpy(&buf[(2000-4)],"..."); } - result = std::string(buffer); + result = string(buffer); free(buffer); } return result; #if 0 // Maybe ok, but not recommended. data() is const char* - std::string result; + string result; va_list ap; va_start(ap,fmt); result.reserve(200); @@ -156,16 +157,16 @@ std::string format(const char *fmt, ...) } // Absolutely identical to format above. This sucks... -std::string format1(const char *fmt, ...) +string format1(const char *fmt, ...) { va_list ap; char buf[200]; va_start(ap,fmt); int n = vsnprintf(buf,199,fmt,ap); va_end(ap); - std::string result; + string result; if (n <= 199) { - result = std::string(buf); + result = string(buf); } else { if (n > 5000) { LOG(ERR) << "oversized string in format"; n = 5000; } // We could use vasprintf but we already computed the length... @@ -175,13 +176,13 @@ std::string format1(const char *fmt, ...) vsnprintf(buffer,n+1,fmt,ap); va_end(ap); //if (n >= (2000-4)) { strcpy(&buf[(2000-4)],"..."); } - result = std::string(buffer); + result = string(buffer); free(buffer); } return result; } -int myscanf(const char *str, const char *fmt, std::string *s1) +int myscanf(const char *str, const char *fmt, string *s1) { int maxlen = strlen(str)+1; char *a1 = (char*)alloca(maxlen); @@ -189,7 +190,7 @@ int myscanf(const char *str, const char *fmt, std::string *s1) s1->assign(a1); return n; } -int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2) +int myscanf(const char *str, const char *fmt, string *s1, string *s2) { int maxlen = strlen(str)+1; char *a1 = (char*)alloca(maxlen); @@ -201,7 +202,7 @@ int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2) } return n; } -int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2, std::string *s3) +int myscanf(const char *str, const char *fmt, string *s1, string *s2, string *s3) { int maxlen = strlen(str)+1; char *a1 = (char*)alloca(maxlen); @@ -215,7 +216,7 @@ int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2, } return n; } -int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2, std::string *s3, std::string *s4) +int myscanf(const char *str, const char *fmt, string *s1, string *s2, string *s3, string *s4) { int maxlen = strlen(str)+1; char *a1 = (char*)alloca(maxlen); @@ -233,25 +234,25 @@ int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2, } #if 0 -std::string format(const char *fmt, std::string s1) { +string format(const char *fmt, string s1) { return format(fmt,s1.c_str()); } -std::string format(const char *fmt, std::string s1, std::string s2) { +string format(const char *fmt, string s1, string s2) { return format(fmt,s1.c_str(),s2.c_str()); } -std::string format(const char *fmt, std::string s1, std::string s2, std::string s3) { +string format(const char *fmt, string s1, string s2, string s3) { return format(fmt,s1.c_str(),s2.c_str(),s3.c_str()); } -std::string format(const char *fmt, std::string s1, int i1) { +string format(const char *fmt, string s1, int i1) { return format(fmt,s1.c_str(),i1); } -std::string format(const char *fmt, int i1, std::string s1) { +string format(const char *fmt, int i1, string s1) { return format(fmt,i1,s1.c_str()); } -std::string format(const char *fmt, std::string s1, std::string s2, int i1) { +string format(const char *fmt, string s1, string s2, int i1) { return format(fmt,s1.c_str(),s2.c_str(),i1); } -std::string format(const char *fmt, std::string s1, std::string s2, int i1, int i2) { +string format(const char *fmt, string s1, string s2, int i1, int i2) { return format(fmt,s1.c_str(),s2.c_str(),i1,i2); } #endif @@ -265,14 +266,14 @@ double timef() return tv.tv_usec / 1000000.0 + tv.tv_sec; } -const std::string timestr(unsigned fieldwidth, bool addDate) // Use to pick the number of chars in the output. +const string timestr(unsigned fieldwidth, bool addDate) // Use to pick the number of chars in the output. { struct timeval tv; struct tm tm; gettimeofday(&tv,NULL); localtime_r(&tv.tv_sec,&tm); unsigned tenths = tv.tv_usec / 100000; // Rounding down is ok. - std::string result; + string result; if (addDate) result = format(" %04d/%02d/%02d %02d:%02d:%02d.%1d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, @@ -288,7 +289,7 @@ const std::string timestr(unsigned fieldwidth, bool addDate) // Use to pick the //} } -const std::string timestr() { return timestr(12); } +const string timestr() { return timestr(12); } // High resolution sleep for the specified time. // Return FALSE if time is already past. @@ -307,16 +308,16 @@ void sleepf(double howlong) //sleepf(sleeptime); //} -std::string Text2Str::str() const +string Text2Str::str() const { - std::ostringstream ss; + ostringstream ss; text(ss); return ss.str(); } -std::ostream& operator<<(std::ostream& os, const Text2Str *val) +ostream& operator<<(std::ostream& os, const Text2Str *val) { - std::ostringstream ss; + ostringstream ss; if (val) { val->text(ss); os << ss.str(); @@ -385,7 +386,7 @@ char *cstrGetArg(const char *in, int nth, unsigned *length) } -std::vector& stringSplit(std::vector &result,const char *input) +vector& stringSplit(vector &result,const char *input) { char *argv[40]; //char buf[202]; @@ -393,18 +394,18 @@ std::vector& stringSplit(std::vector &result,const cha char *buf = strdup(input); int cnt = cstrSplit(buf,argv,40,NULL); for (int i = 0; i < cnt; i++) { - result.push_back(std::string(argv[i])); + result.push_back(string(argv[i])); } free(buf); return result; } -// Print a table formatted as a std::vector of vector of strings. +// Print a table formatted as a vector of vector of strings. // The columns will be aligned. // Column size is determined from the columns. // An entry of "_" is suppressed. -void printPrettyTable(prettyTable_t &tab, std::ostream&os, bool tabSeparated) +void printPrettyTable(prettyTable_t &tab, ostream&os, bool tabSeparated) { LOG(DEBUG); const unsigned maxcols = 30; @@ -412,17 +413,17 @@ void printPrettyTable(prettyTable_t &tab, std::ostream&os, bool tabSeparated) int width[maxcols]; memset(width,0,sizeof(width)); if (!tabSeparated) { for (prettyTable_t::iterator it = tab.begin(); it != tab.end(); ++it) { - std::vector &row = *it; + vector &row = *it; for (unsigned col = 0; col 100) colwidth = 100; - width[col] = std::max(width[col],colwidth); + width[col] = max(width[col],colwidth); } } } // Now print it. for (unsigned nrow = 0; nrow < tab.size(); nrow++) { - std::vector &row = tab[nrow]; + vector &row = tab[nrow]; // DEBUG: print the column widths. if (0 && IS_LOG_LEVEL(DEBUG) && nrow == 0) { @@ -450,25 +451,25 @@ void printPrettyTable(prettyTable_t &tab, std::ostream&os, bool tabSeparated) } os << "\n"; } - os << std::endl; + os << endl; } -std::ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } -std::ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } -std::ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } -std::ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } +ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } +ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } +ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } +ostream& operator<<(std::ostream& os, const Statistic &stat) { stat.text(os); return os; } -std::string replaceAll(const std::string input, const std::string search, const std::string replace) +string replaceAll(const std::string input, const std::string search, const std::string replace) { - std::string output = input; + string output = input; unsigned index1 = 0; while (index1 < output.size()) { try { index1 = output.find(search, index1); - if (index1 == std::string::npos) { + if (index1 == string::npos) { break; } @@ -485,9 +486,9 @@ std::string replaceAll(const std::string input, const std::string search, const } // Efficient string concatenation. -std::string stringcat(std::string a, std::string b, std::string c, std::string d, std::string e, std::string f, std::string g) +string stringcat(string a, string b, string c, string d, string e, string f, string g) { - std::string result; + string result; result.reserve(a.size() + b.size() + c.size() + d.size() + e.size() + f.size() + g.size()); result.append(a); result.append(b); @@ -499,58 +500,58 @@ std::string stringcat(std::string a, std::string b, std::string c, std::string d return result; } -static std::string emptystring(""); +static string emptystring(""); -std::string stringcat(std::string a, std::string b) { +string stringcat(string a, string b) { return stringcat(a,b,emptystring,emptystring,emptystring,emptystring,emptystring); } -std::string stringcat(std::string a, std::string b, std::string c) { +string stringcat(string a, string b, string c) { return stringcat(a,b,c,emptystring,emptystring,emptystring,emptystring); } -std::string stringcat(std::string a, std::string b, std::string c, std::string d) { +string stringcat(string a, string b, string c, string d) { return stringcat(a,b,c,d,emptystring,emptystring,emptystring); } -std::string stringcat(std::string a, std::string b, std::string c, std::string d, std::string e) { +string stringcat(string a, string b, string c, string d, string e) { return stringcat(a,b,c,d,e,emptystring,emptystring); } -std::string stringcat(std::string a, std::string b, std::string c, std::string d, std::string e, std::string f) { +string stringcat(string a, string b, string c, string d, string e, string f) { return stringcat(a,b,c,d,e,f,emptystring); } -void stringToUint(std::string strRAND, uint64_t *hRAND, uint64_t *lRAND) +void stringToUint(string strRAND, uint64_t *hRAND, uint64_t *lRAND) { assert(strRAND.size() == 32); - std::string strhRAND = strRAND.substr(0, 16); - std::string strlRAND = strRAND.substr(16, 16); - std::stringstream ssh; - ssh << std::hex << strhRAND; + string strhRAND = strRAND.substr(0, 16); + string strlRAND = strRAND.substr(16, 16); + stringstream ssh; + ssh << hex << strhRAND; ssh >> *hRAND; - std::stringstream ssl; - ssl << std::hex << strlRAND; + stringstream ssl; + ssl << hex << strlRAND; ssl >> *lRAND; } -std::string uintToString(uint64_t h, uint64_t l) +string uintToString(uint64_t h, uint64_t l) { - std::ostringstream os1; + ostringstream os1; os1.width(16); os1.fill('0'); - os1 << std::hex << h; - std::ostringstream os2; + os1 << hex << h; + ostringstream os2; os2.width(16); os2.fill('0'); - os2 << std::hex << l; - std::ostringstream os3; + os2 << hex << l; + ostringstream os3; os3 << os1.str() << os2.str(); return os3.str(); } -std::string uintToString(uint32_t x) +string uintToString(uint32_t x) { - std::ostringstream os; + ostringstream os; os.width(8); os.fill('0'); - os << std::hex << x; + os << hex << x; return os.str(); } }; diff --git a/Utils.h b/Utils.h index 5e19c2b..7f63596 100644 --- a/Utils.h +++ b/Utils.h @@ -36,40 +36,40 @@ extern const std::string timestr(unsigned fieldwidth, bool addDate = false); // extern void sleepf(double howlong); // high resolution sleep extern int gcd(int x, int y); -std::string format(const char *fmt, ...) __attribute__((format (printf,1,2))); +string format(const char *fmt, ...) __attribute__((format (printf,1,2))); // format1 used to prevent C++ confusion over what function to call here. -std::string format1(const char *fmt, ...) __attribute__((format (printf,1,2))); +string format1(const char *fmt, ...) __attribute__((format (printf,1,2))); // We have to enumerate the cross product of argument types here. This is fixed in C++11. -inline std::string format(const char *fmt, std::string s1) { +inline string format(const char *fmt, string s1) { return format1(fmt,s1.c_str()); } -inline std::string format(const char *fmt, std::string s1, std::string s2) { +inline string format(const char *fmt, string s1, string s2) { return format1(fmt,s1.c_str(),s2.c_str()); } -inline std::string format(const char *fmt, std::string s1, std::string s2, std::string s3) { +inline string format(const char *fmt, string s1, string s2, string s3) { return format1(fmt,s1.c_str(),s2.c_str(),s3.c_str()); } -inline std::string format(const char *fmt, std::string s1, std::string s2, std::string s3, std::string s4) { +inline string format(const char *fmt, string s1, string s2, string s3, string s4) { return format1(fmt,s1.c_str(),s2.c_str(),s3.c_str(),s4.c_str()); } -inline std::string format(const char *fmt, std::string s1, int i1) { +inline string format(const char *fmt, string s1, int i1) { return format1(fmt,s1.c_str(),i1); } -inline std::string format(const char *fmt, int i1, std::string s1) { +inline string format(const char *fmt, int i1, string s1) { return format1(fmt,i1,s1.c_str()); } -inline std::string format(const char *fmt, std::string s1, std::string s2, int i1) { +inline string format(const char *fmt, string s1, string s2, int i1) { return format1(fmt,s1.c_str(),s2.c_str(),i1); } -inline std::string format(const char *fmt, std::string s1, std::string s2, int i1, int i2) { +inline string format(const char *fmt, string s1, string s2, int i1, int i2) { return format1(fmt,s1.c_str(),s2.c_str(),i1,i2); } -int myscanf(const char *str, const char *fmt, std::string *s1); -int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2); -int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2, std::string *s3); -int myscanf(const char *str, const char *fmt, std::string *s1, std::string *s2, std::string *s3, std::string *s4); +int myscanf(const char *str, const char *fmt, string *s1); +int myscanf(const char *str, const char *fmt, string *s1, string *s2); +int myscanf(const char *str, const char *fmt, string *s1, string *s2, string *s3); +int myscanf(const char *str, const char *fmt, string *s1, string *s2, string *s3, string *s4); int cstrSplit(char *in, char **pargv,int maxargc, const char *splitchars=NULL); char *cstrGetArg(const char *in, int nth, unsigned *length); @@ -178,21 +178,21 @@ std::ostream &osprintf(std::ostream &os, const char *fmt, ...) __attribute__((fo std::string replaceAll(const std::string input, const std::string search, const std::string replace); -std::vector& stringSplit(std::vector &result,const char *input); -typedef std::vector > prettyTable_t; -void printPrettyTable(prettyTable_t &tab, std::ostream&os, bool tabSeparated = false); +vector& stringSplit(vector &result,const char *input); +typedef vector > prettyTable_t; +void printPrettyTable(prettyTable_t &tab, ostream&os, bool tabSeparated = false); // The need for this is eliminated in C++11. -std::string stringcat(std::string a, std::string b); -std::string stringcat(std::string a, std::string b, std::string c); -std::string stringcat(std::string a, std::string b, std::string c, std::string d); -std::string stringcat(std::string a, std::string b, std::string c, std::string d, std::string e); -std::string stringcat(std::string a, std::string b, std::string c, std::string d, std::string e, std::string f); -std::string stringcat(std::string a, std::string b, std::string c, std::string d, std::string e, std::string f, std::string g); +string stringcat(string a, string b); +string stringcat(string a, string b, string c); +string stringcat(string a, string b, string c, string d); +string stringcat(string a, string b, string c, string d, string e); +string stringcat(string a, string b, string c, string d, string e, string f); +string stringcat(string a, string b, string c, string d, string e, string f, string g); -extern void stringToUint(std::string strRAND, uint64_t *hRAND, uint64_t *lRAND); -extern std::string uintToString(uint64_t h, uint64_t l); -extern std::string uintToString(uint32_t x); +extern void stringToUint(string strRAND, uint64_t *hRAND, uint64_t *lRAND); +extern string uintToString(uint64_t h, uint64_t l); +extern string uintToString(uint32_t x); // The class is created with a RefCnt of 0. The caller must assign the constructed result to a pointer // of type RefCntPointer. When the last RefCntPointer is freed, this struct is too. diff --git a/VectorTest.cpp b/VectorTest.cpp index bf207c8..4065968 100644 --- a/VectorTest.cpp +++ b/VectorTest.cpp @@ -32,6 +32,8 @@ #include "Configuration.h" ConfigurationTable gConfig; +using namespace std; + typedef Vector TestVector; int barfo; void foo(TestVector a) @@ -40,16 +42,16 @@ void foo(TestVector a) } void anotherTest() { - std::cout << "START Vector anotherTest" << std::endl; + cout << "START Vector anotherTest" << endl; TestVector v0(10); TestVector atest = v0.head(3); - std::cout << atest << std::endl; - std::cout << "calling head" << std::endl; - std::cout << v0.head(3) << std::endl; - std::cout << "Passing Vector" << std::endl; + cout << atest << endl; + cout << "calling head" << endl; + cout << v0.head(3) << endl; + cout << "Passing Vector" << endl; // This calls the Vector non-const copy constructor foo(v0); - std::cout << "FINISH anotherTest" << std::endl; + cout << "FINISH anotherTest" << endl; } int main(int argc, char *argv[]) @@ -60,26 +62,26 @@ int main(int argc, char *argv[]) TestVector test2(5); for (int i=0; i<5; i++) test2[i]=10+i; - std::cout << test1 << std::endl; - std::cout << test2 << std::endl; + cout << test1 << endl; + cout << test2 << endl; { TestVector testC(test1,test2); - std::cout << testC << std::endl; + cout << testC << endl; TestVector foo = testC.head(3); - //std::cout << testC.head(3) << std::endl; - std::cout << testC.tail(3) << std::endl; + //cout << testC.head(3) << endl; + cout << testC.tail(3) << endl; testC.fill(8); - std::cout << testC << std::endl; + cout << testC << endl; test1.copyToSegment(testC,3); - std::cout << testC << std::endl; + cout << testC << endl; TestVector testD(testC.segment(4,3)); - std::cout << testD << std::endl; + cout << testD << endl; testD.fill(9); - std::cout << testC << std::endl; - std::cout << testD << std::endl; + cout << testC << endl; + cout << testD << endl; } return 0; diff --git a/sqlite3util.cpp b/sqlite3util.cpp index 37296f1..ddffe69 100644 --- a/sqlite3util.cpp +++ b/sqlite3util.cpp @@ -14,6 +14,8 @@ #include #include +using namespace std; + // Wrappers to sqlite operations. // These will eventually get moved to commonlibs. @@ -119,13 +121,13 @@ sqlQuery::~sqlQuery() if (mStmt) sqlite3_finalize(mStmt); } -std::string sqlQuery::getResultText(int colNum) +string sqlQuery::getResultText(int colNum) { if (sqlSuccess()) { const char* ptr = (const char*)sqlite3_column_text(mStmt,colNum); - return ptr ? std::string(ptr,sqlite3_column_bytes(mStmt,colNum)) : std::string(""); + return ptr ? string(ptr,sqlite3_column_bytes(mStmt,colNum)) : string(""); } - return std::string(""); + return string(""); } sqlite3_int64 sqlQuery::getResultInt(int colNum) @@ -206,16 +208,16 @@ sqlite3_stmt *sqlite_lookup_row_u(sqlite3*db, const char *tableName, const char* return sqlite_lookup_row(db,tableName,condition_u(conditionBuffer,keyName,keyValue),resultColumns); } // Pass a comma-separated list of column names to return, or if you want all the columns in the result, pass "*" as the resultColumns. -std::vector sqlite_multi_lookup_vector(sqlite3* db, const char* tableName, const char* keyName, const char* keyData, const char *resultColumns) +vector sqlite_multi_lookup_vector(sqlite3* db, const char* tableName, const char* keyName, const char* keyData, const char *resultColumns) { - std::vector result; + vector result; if (sqlite3_stmt *stmt = sqlite_lookup_row_c(db,tableName,keyName,keyData,resultColumns)) { int n = sqlite3_column_count(stmt); if (n < 0 || n > 100) { goto done; } // Would like to LOG an error but afraid to use LOG in here. result.reserve(n+1); for (int i = 0; i < n; i++) { const char* ptr = (const char*)sqlite3_column_text(stmt,i); - result.push_back(ptr ? std::string(ptr,sqlite3_column_bytes(stmt,i)) : std::string("")); + result.push_back(ptr ? string(ptr,sqlite3_column_bytes(stmt,i)) : string("")); } done: sqlite3_finalize(stmt); @@ -227,7 +229,7 @@ std::vector sqlite_multi_lookup_vector(sqlite3* db, const char* tab bool sqlite_single_lookup(sqlite3* db, const char* tableName, const char* keyName, const char* keyData, - const char* resultName, std::string &resultData) + const char* resultName, string &resultData) { sqlQuery query(db,tableName,resultName,keyName,keyData); if (query.sqlSuccess()) { @@ -238,7 +240,7 @@ bool sqlite_single_lookup(sqlite3* db, const char* tableName, #if 0 if (sqlite3_stmt *stmt = sqlite_lookup_row_c(db,tableName,keyName,keyData,valueName)) { if (const char* ptr = (const char*)sqlite3_column_text(stmt,0)) { - valueData = std::string(ptr,sqlite3_column_bytes(stmt,0)); + valueData = string(ptr,sqlite3_column_bytes(stmt,0)); } sqlite3_finalize(stmt); return true; @@ -249,7 +251,7 @@ bool sqlite_single_lookup(sqlite3* db, const char* tableName, bool sqlite_single_lookup(sqlite3* db, const char* tableName, const char* keyName, unsigned keyValue, - const char* resultName, std::string &resultData) + const char* resultName, string &resultData) { sqlQuery query(db,tableName,resultName,keyName,keyValue); if (query.sqlSuccess()) { @@ -260,7 +262,7 @@ bool sqlite_single_lookup(sqlite3* db, const char* tableName, #if 0 if (sqlite3_stmt *stmt = sqlite_lookup_row_u(db,tableName,keyName,keyValue,valueName)) { if (const char* ptr = (const char*)sqlite3_column_text(stmt,0)) { - valueData = std::string(ptr,sqlite3_column_bytes(stmt,0)); + valueData = string(ptr,sqlite3_column_bytes(stmt,0)); } sqlite3_finalize(stmt); return true; @@ -271,12 +273,12 @@ bool sqlite_single_lookup(sqlite3* db, const char* tableName, // Do the lookup and just return the string. // For this function an empty value is indistinguishable from failure - both return an empty string. -std::string sqlite_single_lookup_string(sqlite3* db, const char* tableName, +string sqlite_single_lookup_string(sqlite3* db, const char* tableName, const char* keyName, const char* keyData, const char* resultName) { return sqlQuery(db,tableName,resultName,keyName,keyData).getResultText(); #if 0 - std::string result; + string result; (void) sqlite_single_lookup(db,tableName,keyName,keyData,valueName,result); return result; #endif @@ -349,7 +351,7 @@ bool sqlite_set_attr(sqlite3*db,const char *attr_name,const char*attr_value) return true; } -std::string sqlite_get_attr(sqlite3*db,const char *attr_name) +string sqlite_get_attr(sqlite3*db,const char *attr_name) { return sqlite_single_lookup_string(db,"ATTR_TABLE","ATTR_NAME",attr_name,"ATTR_VALUE"); }