Ignore:
Timestamp:
10/18/13 16:54:42 (11 years ago)
Author:
tbretz
Message:
Removed the 'using namespace std;' from the header.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/fits.h

    r17259 r17260  
    4848namespace std
    4949{
    50 #else
    51 using namespace std;
    5250#endif
    5351
     
    6563    struct Entry
    6664    {
    67         char   type;
    68         string value;
    69         string comment;
    70         string fitsString;
     65        char        type;
     66        std::string value;
     67        std::string comment;
     68        std::string fitsString;
    7169
    7270        template<typename T>
     
    7573            T t;
    7674
    77             istringstream str(value);
     75            std::istringstream str(value);
    7876            str >> t;
    7977
     
    8886        bool is_compressed;
    8987
    90         string name;
     88        std::string name;
    9189        size_t bytes_per_row;
    9290        size_t num_rows;
     
    10199            size_t bytes;  // num*size
    102100            char   type;
    103             string unit;
     101            std::string unit;
    104102            Compression_t comp;
    105103        };
    106104
    107         typedef map<string, Entry>  Keys;
    108         typedef map<string, Column> Columns;
    109         typedef vector<Column> SortedColumns;
     105        typedef std::map<std::string, Entry>  Keys;
     106        typedef std::map<std::string, Column> Columns;
     107        typedef std::vector<Column> SortedColumns;
    110108
    111109        Columns cols;
     
    115113        int64_t datasum;
    116114
    117         string Trim(const string &str, char c=' ') const
     115        std::string Trim(const std::string &str, char c=' ') const
    118116        {
    119117            // Trim Both leading and trailing spaces
     
    122120
    123121            // if all spaces or empty return an empty string
    124             if (string::npos==pstart || string::npos==pend)
    125                 return string();
     122            if (std::string::npos==pstart || std::string::npos==pend)
     123                return std::string();
    126124
    127125            return str.substr(pstart, pend-pstart+1);
    128126        }
    129127
    130         bool Check(const string &key, char type, const string &value="") const
     128        bool Check(const std::string &key, char type, const std::string &value="") const
    131129        {
    132130            const Keys::const_iterator it = keys.find(key);
    133131            if (it==keys.end())
    134132            {
    135                 ostringstream str;
     133                std::ostringstream str;
    136134                str << "Key '" << key << "' not found.";
    137135#ifdef __EXCEPTIONS
    138                 throw runtime_error(str.str());
     136                throw std::runtime_error(str.str());
    139137#else
    140138                gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    145143            if (it->second.type!=type)
    146144            {
    147                 ostringstream str;
     145                std::ostringstream str;
    148146                str << "Wrong type for key '" << key << "': expected " << type << ", found " << it->second.type << ".";
    149147#ifdef __EXCEPTIONS
    150                 throw runtime_error(str.str());
     148                throw std::runtime_error(str.str());
    151149#else
    152150                gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    157155            if (!value.empty() && it->second.value!=value)
    158156            {
    159                 ostringstream str;
     157                std::ostringstream str;
    160158                str << "Wrong value for key '" << key << "': expected " << value << ", found " << it->second.value << ".";
    161159#ifdef __EXCEPTIONS
    162                 throw runtime_error(str.str());
     160                throw std::runtime_error(str.str());
    163161#else
    164162                gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    170168        }
    171169
    172         Keys ParseBlock(const vector<string> &vec) const
    173         {
    174             map<string,Entry> rc;
     170        Keys ParseBlock(const std::vector<std::string> &vec) const
     171        {
     172            std::map<std::string,Entry> rc;
    175173
    176174            for (unsigned int i=0; i<vec.size(); i++)
    177175            {
    178                 const string key = Trim(vec[i].substr(0,8));
     176                const std::string key = Trim(vec[i].substr(0,8));
    179177                // Keywords without a value, like COMMENT / HISTORY
    180178                if (vec[i].substr(8,2)!="= ")
     
    183181                char type = 0;
    184182
    185                 string com;
    186                 string val = Trim(vec[i].substr(10));
     183                std::string com;
     184                std::string val = Trim(vec[i].substr(10));
    187185
    188186                if (val[0]=='\'')
     
    193191                    {
    194192                        const size_t pp = val.find_first_of('\'', p);
    195                         if (pp==string::npos)
     193                        if (pp==std::string::npos)
    196194                            break;
    197195
     
    204202                    // Set value, comment and type
    205203                    // comments could be just spaces. take care of this.
    206                     if (ppp!=string::npos && val.size() != ppp+1)
     204                    if (ppp!=std::string::npos && val.size() != ppp+1)
    207205                        com = Trim(val.substr(ppp+1));
    208206
     
    219217                    val = Trim(val.substr(0, p));
    220218
    221                     if (val.empty() || val.find_first_of('T')!=string::npos || val.find_first_of('F')!=string::npos)
     219                    if (val.empty() || val.find_first_of('T')!=std::string::npos || val.find_first_of('F')!=std::string::npos)
    222220                        type = 'B';
    223221                    else
    224                         type = val.find_last_of('.')==string::npos ? 'I' : 'F';
     222                        type = val.find_last_of('.')==std::string::npos ? 'I' : 'F';
    225223                }
    226224
     
    234232
    235233        Table() : offset(0), is_compressed(false) { }
    236         Table(const vector<string> &vec, off_t off) : offset(off),
     234        Table(const std::vector<std::string> &vec, off_t off) : offset(off),
    237235            keys(ParseBlock(vec))
    238236        {
     
    270268            size_t bytes = 0;
    271269
    272             const string tFormName = is_compressed ? "ZFORM" : "TFORM";
     270            const std::string tFormName = is_compressed ? "ZFORM" : "TFORM";
    273271            for (long long unsigned int i=1; i<=num_cols; i++)
    274272            {
    275                 const string num(to_string(i));
     273                const std::string num(std::to_string(i));
    276274
    277275                if (!Check("TTYPE"+num, 'T') ||
     
    279277                    return;
    280278
    281                 const string id   = Get<string>("TTYPE"+num);
    282                 const string fmt  = Get<string>(tFormName+num);
    283                 const string unit = Get<string>("TUNIT"+num, "");
    284                 const string comp = Get<string>("ZCTYP"+num, "");
     279                const std::string id   = Get<std::string>("TTYPE"+num);
     280                const std::string fmt  = Get<std::string>(tFormName+num);
     281                const std::string unit = Get<std::string>("TUNIT"+num, "");
     282                const std::string comp = Get<std::string>("ZCTYP"+num, "");
    285283
    286284                Compression_t compress = kCompUnknown;
     
    288286                    compress = kCompFACT;
    289287
    290                 istringstream sin(fmt);
     288                std::istringstream sin(fmt);
    291289                int n = 0;
    292290                sin >> n;
     
    316314                default:
    317315                    {
    318                         ostringstream str;
     316                        std::ostringstream str;
    319317                        str << "FITS format TFORM='" << fmt << "' not yet supported.";
    320318#ifdef __EXCEPTIONS
    321                         throw runtime_error(str.str());
     319                        throw std::runtime_error(str.str());
    322320#else
    323321                        gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    337335            {
    338336#ifdef __EXCEPTIONS
    339                 throw runtime_error("Column size mismatch");
     337                throw std::runtime_error("Column size mismatch");
    340338#else
    341339                gLog << ___err___ << "ERROR - Column size mismatch" << endl;
     
    344342            }
    345343
    346             name = Get<string>("EXTNAME");
     344            name = Get<std::string>("EXTNAME");
    347345        }
    348346
    349347        void PrintKeys(bool display_all=false) const
    350348        {
    351             for (Keys::const_iterator it=keys.begin(); it!=keys.end(); it++)
     349            for (Keys::const_iterator it=keys.cbegin(); it!=keys.cend(); it++)
    352350            {
    353351                if (!display_all &&
     
    369367        void PrintColumns() const
    370368        {
    371             typedef map<pair<size_t, string>, Column> Sorted;
     369            typedef std::map<std::pair<size_t, std::string>, Column> Sorted;
    372370
    373371            Sorted sorted;
    374372
    375             for (Columns::const_iterator it=cols.begin(); it!=cols.end(); it++)
    376                 sorted[make_pair(it->second.offset, it->first)] = it->second;
    377 
    378             for (Sorted::const_iterator it=sorted.begin(); it!=sorted.end(); it++)
     373            for (Columns::const_iterator it=cols.cbegin(); it!=cols.cend(); it++)
     374                sorted[std::make_pair(it->second.offset, it->first)] = it->second;
     375
     376            for (Sorted::const_iterator it=sorted.cbegin(); it!=sorted.cend(); it++)
    379377            {
    380378                gLog << ___all___ << setw(6) << it->second.offset << "| ";
     
    397395        operator bool() const { return !name.empty(); }
    398396
    399         bool HasKey(const string &key) const
     397        bool HasKey(const std::string &key) const
    400398        {
    401399            return keys.find(key)!=keys.end();
    402400        }
    403401
    404         bool HasColumn(const string& col) const
     402        bool HasColumn(const std::string& col) const
    405403        {
    406404            return cols.find(col)!=cols.end();
     
    419417        // Values of keys are always signed
    420418        template<typename T>
    421             T Get(const string &key) const
    422         {
    423             const map<string,Entry>::const_iterator it = keys.find(key);
     419            T Get(const std::string &key) const
     420        {
     421            const std::map<std::string,Entry>::const_iterator it = keys.find(key);
    424422            if (it==keys.end())
    425423            {
    426                 ostringstream str;
    427                 str << "Key '" << key << "' not found." << endl;
    428 #ifdef __EXCEPTIONS
    429                 throw runtime_error(str.str());
     424                std::ostringstream str;
     425                str << "Key '" << key << "' not found.";
     426#ifdef __EXCEPTIONS
     427                throw std::runtime_error(str.str());
    430428#else
    431429                gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    438436        // Values of keys are always signed
    439437        template<typename T>
    440             T Get(const string &key, const T &deflt) const
    441         {
    442             const map<string,Entry>::const_iterator it = keys.find(key);
     438            T Get(const std::string &key, const T &deflt) const
     439        {
     440            const std::map<std::string,Entry>::const_iterator it = keys.find(key);
    443441            return it==keys.end() ? deflt :it->second.Get<T>();
    444442        }
    445443
    446         size_t GetN(const string &key) const
     444        size_t GetN(const std::string &key) const
    447445        {
    448446            const Columns::const_iterator it = cols.find(key);
     
    485483
    486484protected:
    487     ofstream fCopy;
     485    std::ofstream fCopy;
    488486
    489487    Table fTable;
    490488
    491     typedef pair<void*, Table::Column> Address;
    492     typedef vector<Address> Addresses;
     489    typedef std::pair<void*, Table::Column> Address;
     490    typedef std::vector<Address> Addresses;
    493491    //map<void*, Table::Column> fAddresses;
    494492    Addresses fAddresses;
    495493
    496494#if defined(__MARS__) || defined(__CINT__)
    497     typedef map<string, void*> Pointers;
    498 #else
    499     typedef unordered_map<string, void*> Pointers;
     495    typedef std::map<std::string, void*> Pointers;
     496#else
     497    typedef std::unordered_map<std::string, void*> Pointers;
    500498#endif
    501499    Pointers fPointers;
    502500
    503     vector<vector<char>> fGarbage;
    504 
    505     vector<char> fBufferRow;
    506     vector<char> fBufferDat;
     501    std::vector<std::vector<char>> fGarbage;
     502
     503    std::vector<char> fBufferRow;
     504    std::vector<char> fBufferDat;
    507505
    508506    size_t fRow;
     
    511509    Checksum fChkData;
    512510
    513     bool ReadBlock(vector<string> &vec)
     511    bool ReadBlock(std::vector<std::string> &vec)
    514512    {
    515513        int endtag = 0;
     
    527525//                return vector<string>();
    528526
    529             string str(c);
     527            std::string str(c);
    530528
    531529//            if (!str.empty())
     
    554552    }
    555553
    556     string Compile(const string &key, int16_t i=-1) const
    557     {
    558         if (i<0)
    559             return key;
    560 
    561         ostringstream str;
    562         str << key << i;
    563         return str.str();
     554    std::string Compile(const std::string &key, int16_t i=-1) const
     555    {
     556        return i<0 ? key : key+std::to_string(i);
    564557    }
    565558
     
    577570            clear(rdstate()|ios::badbit);
    578571#ifdef __EXCEPTIONS
    579             throw runtime_error("File is not a FITS file.");
     572            throw std::runtime_error("File is not a FITS file.");
    580573#else
    581574            gLog << ___err___ << "ERROR - File is not a FITS file." << endl;
     
    588581        while (good())
    589582        {
    590             vector<string> block;
     583            std::vector<std::string> block;
    591584            while (1)
    592585            {
     
    605598                    clear(rdstate()|ios::badbit);
    606599#ifdef __EXCEPTIONS
    607                     throw runtime_error("FITS file corrupted.");
     600                    throw std::runtime_error("FITS file corrupted.");
    608601#else
    609602                    gLog << ___err___ << "ERROR - FITS file corrupted." << endl;
     
    618611                        clear(rdstate()|ios::badbit);
    619612#ifdef __EXCEPTIONS
    620                         throw runtime_error("END keyword missing in FITS header.");
     613                        throw std::runtime_error("END keyword missing in FITS header.");
    621614#else
    622615                        gLog << ___err___ << "ERROR - END keyword missing in FITS file... file might be corrupted." << endl;
     
    691684            clear(rdstate()|ios::badbit);
    692685#ifdef __EXCEPTIONS
    693             throw runtime_error("Could not open output file.");
     686            throw std::runtime_error("Could not open output file.");
    694687#else
    695688            gLog << ___err___ << "ERROR - Failed to open output file." << endl;
     
    700693        seekg(0);
    701694
    702         vector<char> buf(p);
     695        std::vector<char> buf(p);
    703696        read(buf.data(), p);
    704697
     
    709702
    710703public:
    711     fits(const string &fname, const string& tableName="", bool force=false) : izstream(fname.c_str())
     704    fits(const std::string &fname, const std::string& tableName="", bool force=false) : izstream(fname.c_str())
    712705    {
    713706        Constructor(fname, "", tableName, force);
     
    716709        {
    717710#ifdef __EXCEPTIONS
    718             throw runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
     711            throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
    719712#else
    720713            gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << endl;
     
    724717    }
    725718
    726     fits(const string &fname, const string &fout, const string& tableName, bool force=false) : izstream(fname.c_str())
     719    fits(const std::string &fname, const std::string &fout, const std::string& tableName, bool force=false) : izstream(fname.c_str())
    727720    {
    728721        Constructor(fname, fout, tableName, force);
     
    731724        {
    732725#ifdef __EXCEPTIONS
    733             throw runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
     726            throw std::runtime_error("You are trying to read a compressed fits with the base fits class. Please use factfits instead.");
    734727#else
    735728            gLog << ___err___ << "ERROR - You are trying to read a compressed fits with the base fits class. Please use factfits instead." << endl;
     
    746739    ~fits()
    747740    {
    748         copy(istreambuf_iterator<char>(*this),
    749              istreambuf_iterator<char>(),
    750              ostreambuf_iterator<char>(fCopy));
     741        std::copy(std::istreambuf_iterator<char>(*this),
     742                  std::istreambuf_iterator<char>(),
     743                  std::ostreambuf_iterator<char>(fCopy));
    751744    }
    752745
     
    776769    }
    777770
    778     void ZeroBufferForChecksum(vector<char>& vec, const uint64_t extraZeros=0)
     771    void ZeroBufferForChecksum(std::vector<char>& vec, const uint64_t extraZeros=0)
    779772    {
    780773        auto ib = vec.begin();
     
    842835        const char *ptr = fBufferRow.data() + offset;
    843836
    844         for (Addresses::const_iterator it=fAddresses.begin(); it!=fAddresses.end(); it++)
     837        for (Addresses::const_iterator it=fAddresses.cbegin(); it!=fAddresses.cend(); it++)
    845838        {
    846839            const Table::Column &c = it->second;
     
    876869
    877870    template<class T, class S>
    878     const T &GetAs(const string &name)
     871    const T &GetAs(const std::string &name)
    879872    {
    880873        return *reinterpret_cast<S*>(fPointers[name]);
    881874    }
    882875
    883     void *SetPtrAddress(const string &name)
     876    void *SetPtrAddress(const std::string &name)
    884877    {
    885878        if (fTable.cols.count(name)==0)
    886879        {
    887             ostringstream str;
    888             str << "SetPtrAddress('" << name << "') - Column not found." << endl;
    889 #ifdef __EXCEPTIONS
    890             throw runtime_error(str.str());
     880            std::ostringstream str;
     881            str << "SetPtrAddress('" << name << "') - Column not found.";
     882#ifdef __EXCEPTIONS
     883            throw std::runtime_error(str.str());
    891884#else
    892885            gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    910903
    911904    template<typename T>
    912     bool SetPtrAddress(const string &name, T *ptr, size_t cnt)
     905    bool SetPtrAddress(const std::string &name, T *ptr, size_t cnt)
    913906    {
    914907        if (fTable.cols.count(name)==0)
    915908        {
    916             ostringstream str;
    917             str << "SetPtrAddress('" << name << "') - Column not found." << endl;
    918 #ifdef __EXCEPTIONS
    919             throw runtime_error(str.str());
     909            std::ostringstream str;
     910            str << "SetPtrAddress('" << name << "') - Column not found.";
     911#ifdef __EXCEPTIONS
     912            throw std::runtime_error(str.str());
    920913#else
    921914            gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    926919        if (sizeof(T)!=fTable.cols[name].size)
    927920        {
    928             ostringstream str;
     921            std::ostringstream str;
    929922            str << "SetPtrAddress('" << name << "') - Element size mismatch: expected "
    930                 << fTable.cols[name].size << " from header, got " << sizeof(T) << endl;
    931 #ifdef __EXCEPTIONS
    932             throw runtime_error(str.str());
     923                << fTable.cols[name].size << " from header, got " << sizeof(T);
     924#ifdef __EXCEPTIONS
     925            throw std::runtime_error(str.str());
    933926#else
    934927            gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    939932        if (cnt!=fTable.cols[name].num)
    940933        {
    941             ostringstream str;
     934            std::ostringstream str;
    942935            str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
    943                 << fTable.cols[name].num << " from header, got " << cnt << endl;
    944 #ifdef __EXCEPTIONS
    945             throw runtime_error(str.str());
     936                << fTable.cols[name].num << " from header, got " << cnt;
     937#ifdef __EXCEPTIONS
     938            throw std::runtime_error(str.str());
    946939#else
    947940            gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    961954
    962955    template<class T>
    963     bool SetRefAddress(const string &name, T &ptr)
     956    bool SetRefAddress(const std::string &name, T &ptr)
    964957    {
    965958        return SetPtrAddress(name, &ptr, sizeof(ptr)/sizeof(T));
     
    967960
    968961    template<typename T>
    969     bool SetVecAddress(const string &name, vector<T> &vec)
     962    bool SetVecAddress(const std::string &name, std::vector<T> &vec)
    970963    {
    971964        return SetPtrAddress(name, vec.data(), vec.size());
     
    973966
    974967    template<typename T>
    975         T Get(const string &key) const
     968        T Get(const std::string &key) const
    976969    {
    977970        return fTable.Get<T>(key);
     
    979972
    980973    template<typename T>
    981         T Get(const string &key, const string &deflt) const
     974        T Get(const std::string &key, const std::string &deflt) const
    982975    {
    983976        return fTable.Get<T>(key, deflt);
    984977    }
    985978
    986     bool SetPtrAddress(const string &name, void *ptr, size_t cnt=0)
     979    bool SetPtrAddress(const std::string &name, void *ptr, size_t cnt=0)
    987980    {
    988981        if (fTable.cols.count(name)==0)
    989982        {
    990             ostringstream str;
    991             str <<"SetPtrAddress('" << name << "') - Column not found." << endl;
    992 #ifdef __EXCEPTIONS
    993             throw runtime_error(str.str());
     983            std::ostringstream str;
     984            str <<"SetPtrAddress('" << name << "') - Column not found.";
     985#ifdef __EXCEPTIONS
     986            throw std::runtime_error(str.str());
    994987#else
    995988            gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    1000993        if (cnt && cnt!=fTable.cols[name].num)
    1001994        {
    1002             ostringstream str;
     995            std::ostringstream str;
    1003996            str << "SetPtrAddress('" << name << "') - Element count mismatch: expected "
    1004                 << fTable.cols[name].num << " from header, got " << cnt << endl;
    1005 #ifdef __EXCEPTIONS
    1006             throw runtime_error(str.str());
     997                << fTable.cols[name].num << " from header, got " << cnt;
     998#ifdef __EXCEPTIONS
     999            throw std::runtime_error(str.str());
    10071000#else
    10081001            gLog << ___err___ << "ERROR - " << str.str() << endl;
     
    10211014    }
    10221015
    1023     bool     HasKey(const string &key) const { return fTable.HasKey(key); }
    1024     bool     HasColumn(const string& col) const { return fTable.HasColumn(col);}
     1016    bool     HasKey(const std::string &key) const { return fTable.HasKey(key); }
     1017    bool     HasColumn(const std::string& col) const { return fTable.HasColumn(col);}
    10251018    const Table::Columns &GetColumns() const { return fTable.GetColumns();}
    10261019    const Table::SortedColumns& GetSortedColumns() const { return fTable.sorted_cols;}
    10271020    const Table::Keys &GetKeys() const { return fTable.GetKeys();}
    10281021
    1029     int64_t  GetInt(const string &key) const { return fTable.Get<int64_t>(key); }
    1030     uint64_t GetUInt(const string &key) const { return fTable.Get<uint64_t>(key); }
    1031     double   GetFloat(const string &key) const { return fTable.Get<double>(key); }
    1032     string   GetStr(const string &key) const { return fTable.Get<string>(key); }
    1033 
    1034     size_t GetN(const string &key) const
     1022    int64_t     GetInt(const std::string &key) const { return fTable.Get<int64_t>(key); }
     1023    uint64_t    GetUInt(const std::string &key) const { return fTable.Get<uint64_t>(key); }
     1024    double      GetFloat(const std::string &key) const { return fTable.Get<double>(key); }
     1025    std::string GetStr(const std::string &key) const { return fTable.Get<std::string>(key); }
     1026
     1027    size_t GetN(const std::string &key) const
    10351028    {
    10361029        return fTable.GetN(key);
Note: See TracChangeset for help on using the changeset viewer.