Changeset 257 for cpp/common
- Timestamp:
- 12/03/14 18:52:05 (10 years ago)
- Location:
- cpp/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/Convert.cpp
r247 r257 90 90 #if defined LINUX // || android? 91 91 return *::localtime_r(&timep,&ret); 92 #elif defined _WIN32 && !defined __BORLANDC__ // and not bada?92 #elif defined _WIN32 && !defined __BORLANDC__ 93 93 ::localtime_s(&ret, &timep); 94 94 return ret; … … 115 115 #if defined LINUX // || android? 116 116 ret=::asctime_r(&tm,buf); 117 #elif defined _WIN32 && !defined __BORLANDC__ // and not bada?117 #elif defined _WIN32 && !defined __BORLANDC__ 118 118 asctime_s(buf, sizeof(buf), &tm); 119 119 ret = buf; -
cpp/common/stl-util.cpp
r247 r257 11 11 #include <assert.h> 12 12 #ifdef USE_VIRTFILE 13 13 #include <frams/virtfile/virtfile.h> 14 14 #endif 15 15 #ifdef __BORLANDC__ 16 16 #define va_copy(to,from) to=from //borland does not have va_copy() at all; va_list is just a pointer in borland 17 17 #endif 18 18 … … 27 27 //almost like SString::sprintf, but there is no common code to share because SString can use its directWrite to avoid double allocating/copying 28 28 #ifdef USE_VSCPRINTF 29 va_copy(ap_copy, ap);29 va_copy(ap_copy, ap); 30 30 size = _vscprintf(format, ap_copy) + 1; //+1 for terminating null character 31 31 va_end(ap_copy); … … 36 36 buf = (char*)malloc(size); 37 37 assert(buf != NULL); 38 va_copy(ap_copy, ap);38 va_copy(ap_copy, ap); 39 39 int n = vsnprintf(buf, size, format, ap_copy); 40 40 va_end(ap_copy); … … 55 55 } 56 56 57 char* strmove(char *a, char *b) //strcpy that works well for overlapping strings ("Source and destination overlap") 58 { 59 if (a == NULL || b == NULL) 60 return NULL; 61 memmove(a, b, strlen(b) + 1); 62 return a; 63 } 64 57 65 string ssprintf(const char* format, ...) 58 66 { … … 66 74 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file) 67 75 { 68 bool ok=false;76 bool ok = false; 69 77 #ifdef USE_VIRTFILE 70 78 if (!isAbsolutePath(filename)) 71 79 { 72 80 VirtFILE *f=Vfopen(filename,FOPEN_READ_BINARY); 73 81 if (f) 74 82 { 75 83 int size=f->getSize(); 76 84 data.resize(size); … … 78 86 ok = przeczytane == 1; 79 87 delete f; 80 }81 88 } 89 } 82 90 else 83 91 #endif 84 92 { 85 MFILE *f = mfopen(filename, FOPEN_READ_BINARY);86 if (f)87 {88 int size=getFileSize(f);89 data.resize(size);90 int przeczytane = mfread(&data[0], size, 1, f);91 mfclose(f);92 ok = przeczytane == 1;93 }93 MFILE *f = mfopen(filename, FOPEN_READ_BINARY); 94 if (f) 95 { 96 int size = getFileSize(f); 97 data.resize(size); 98 int przeczytane = mfread(&data[0], size, 1, f); 99 mfclose(f); 100 ok = przeczytane == 1; 101 } 94 102 } 95 103 if (warn_on_missing_file && !ok) -
cpp/common/stl-util.h
r246 r257 11 11 template<typename T, std::size_t N> void push_back(vector<T>& v, T(&d)[N]) 12 12 { 13 for(unsigned int i=0;i<N;i++)14 v.push_back(d[i]);13 for (unsigned int i = 0; i < N; i++) 14 v.push_back(d[i]); 15 15 } 16 16 17 17 template<typename T> void erase(vector<T>& v, const T& e) 18 18 { 19 typename vector<T>::iterator it=std::find(v.begin(),v.end(),e);20 if (it!=v.end())21 v.erase(it);19 typename vector<T>::iterator it = std::find(v.begin(), v.end(), e); 20 if (it != v.end()) 21 v.erase(it); 22 22 } 23 23 24 24 template<typename T> void deleteVectorElements(vector<T*>& v) 25 25 { 26 for(typename vector<T*>::iterator it=v.begin();it!=v.end();it++)27 delete *it;28 v.clear();26 for (typename vector<T*>::iterator it = v.begin(); it != v.end(); it++) 27 delete *it; 28 v.clear(); 29 29 } 30 30 31 31 template<typename T> int findIndex(vector<T>& v, const T& e) 32 32 { 33 typename vector<T>::iterator it=find(v.begin(),v.end(),e);34 if (it!=v.end())35 return &*it-&v.front();36 return -1;33 typename vector<T>::iterator it = find(v.begin(), v.end(), e); 34 if (it != v.end()) 35 return &*it - &v.front(); 36 return -1; 37 37 } 38 39 40 char* strmove(char *a, char *b); //strcpy that works well for overlapping strings ("Source and destination overlap") 38 41 39 42 string ssprintf(const char* format, ...); … … 45 48 46 49 47 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file =true);48 bool readCompleteFile(const char* filename, string& out, bool warn_on_missing_file =true);49 bool writeCompleteFile(const char* filename, const std::string& text, bool warn_on_fail=true);50 bool writeCompleteFile(const char* filename, vector<char>& data, bool warn_on_fail =true);50 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file = true); 51 bool readCompleteFile(const char* filename, string& out, bool warn_on_missing_file = true); 52 bool writeCompleteFile(const char* filename, const std::string& text, bool warn_on_fail = true); 53 bool writeCompleteFile(const char* filename, vector<char>& data, bool warn_on_fail = true); 51 54 52 55 template<class T> class DeletingVector // deletes the elements (pointers) in destructor 53 56 { 54 55 std::vector<T*> vector;56 ~DeletingVector()57 public: 58 std::vector<T*> vector; 59 ~DeletingVector() 57 60 { 58 for(int i=vector.size()-1;i>=0;i--)59 delete vector[i];61 for (int i = vector.size() - 1; i >= 0; i--) 62 delete vector[i]; 60 63 } 61 T* operator[](int i) {return vector[i];}62 int size() {return vector.size();}63 void push_back(T* x) {vector.push_back(x);}64 T* operator[](int i) { return vector[i]; } 65 int size() { return vector.size(); } 66 void push_back(T* x) { vector.push_back(x); } 64 67 }; 65 68
Note: See TracChangeset
for help on using the changeset viewer.