Ignore:
Timestamp:
12/08/18 05:31:09 (5 years ago)
Author:
Maciej Komosinski
Message:

Split stl-util into util-stl, util-file and util-string

File:
1 moved

Legend:

Unmodified
Added
Removed
  • cpp/common/util-string.h

    r839 r840  
    33// See LICENSE.txt for details.
    44
    5 #ifndef _STL_UTIL_H_
    6 #define _STL_UTIL_H_
     5#ifndef _UTIL_STRINGS_H_
     6#define _UTIL_STRINGS_H_
    77
    88#include "nonstd_stl.h"
    99#include <stdarg.h>
    10 
    11 template<typename T, std::size_t N> void push_back(vector<T>& v, T(&d)[N])
    12 {
    13         for (unsigned int i = 0; i < N; i++)
    14                 v.push_back(d[i]);
    15 }
    16 
    17 template<typename T> void erase(vector<T>& v, const T& e)
    18 {
    19         typename vector<T>::iterator it = std::find(v.begin(), v.end(), e);
    20         if (it != v.end())
    21                 v.erase(it);
    22 }
    23 
    24 template<typename T> void deleteVectorElements(vector<T*>& v)
    25 {
    26         for (typename vector<T*>::iterator it = v.begin(); it != v.end(); it++)
    27                 delete *it;
    28         v.clear();
    29 }
    30 
    31 template<typename T> int findIndex(vector<T>& v, const T& e)
    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;
    37 }
    38 
    3910
    4011char* strmove(char *a, char *b); //strcpy that works well for overlapping strings ("Source and destination overlap")
     
    4819string stripFileDir(const string& filename); // strip path component from filename
    4920
    50 
    51 bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file = true);
    52 bool readCompleteFile(const char* filename, string& out, bool warn_on_missing_file = true);
    53 bool writeCompleteFile(const char* filename, const std::string& text, bool warn_on_fail = true);
    54 bool writeCompleteFile(const char* filename, vector<char>& data, bool warn_on_fail = true);
    55 
    56 template<class T> class DeletingVector  // deletes the elements (pointers) in destructor
    57 {
    58 public:
    59         std::vector<T*> vector;
    60         ~DeletingVector()
    61         {
    62                 for (int i = vector.size() - 1; i >= 0; i--)
    63                         delete vector[i];
    64         }
    65         T* operator[](int i) { return vector[i]; }
    66         int size() { return vector.size(); }
    67         void push_back(T* x) { vector.push_back(x); }
    68 };
    69 
    7021#endif
Note: See TracChangeset for help on using the changeset viewer.