update cppcommon

This commit is contained in:
gwdwyy 2013-08-14 17:32:11 +08:00
parent 05879ac6c3
commit 2c77ac8806
2 changed files with 31 additions and 8 deletions

View File

@ -8,7 +8,7 @@ namespace CPPCOMMON
{ {
string loadFile2Str(const char * const filepath) string loadFile2Str(const char * const filepath)
{ {
ifstream in(filepath, ios::in); ifstream in(filepath);
istreambuf_iterator<char> beg(in), end; istreambuf_iterator<char> beg(in), end;
string str(beg, end); string str(beg, end);
in.close(); in.close();

View File

@ -7,12 +7,35 @@
#ifndef CPPCOMMON_MAP_FUNCTS_H #ifndef CPPCOMMON_MAP_FUNCTS_H
#define CPPCOMMON_MAP_FUNCTS_H #define CPPCOMMON_MAP_FUNCTS_H
#define PRINT_MAPSS(mpss) \ #include <map>
{\ #include <iostream>
for(map<string, string>::const_iterator it = mpss.begin(); it != mpss.end(); it++)\
{\ namespace CPPCOMMON
cout<<it->first<<' '<<it->second<<endl;\ {
}\ using namespace std;
template<class kT, class vT>
void printMap(const map<kT, vT>& mp)
{
for(typename map<kT, vT>::const_iterator it = mp.begin(); it != mp.end(); it++)
{
cout<<it->first<<' '<<it->second<<endl;
}
}
template<class kT, class vT>
vT getMap(const map<kT, vT>& mp, const kT & key, const vT & defaultVal)
{
typename map<kT, vT>::const_iterator it;
it = mp.find(key);
if(mp.end() == it)
{
return defaultVal;
}
return it->second;
}
} }
#endif #endif