Changeset 12737


Ignore:
Timestamp:
12/22/11 15:47:41 (13 years ago)
Author:
tbretz
Message:
added an unordered_map to allow access to the read members by name
File:
1 edited

Legend:

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

    r12732 r12737  
    1515#ifdef __CINT__
    1616#define off_t size_t
     17#else
     18#include <unordered_map>
    1719#endif
    1820
     
    399401    Addresses fAddresses;
    400402
     403#ifdef __CINT__
     404    typedef map<string, void*> Pointers;
     405#else
     406    typedef unordered_map<string, void*> Pointers;
     407#endif
     408    Pointers fPointers;
     409
     410    vector<vector<char>> fGarbage;
     411
    401412    vector<char> fBufferRow;
    402413    vector<char> fBufferDat;
     
    614625    }
    615626
     627    template<class T, class S>
     628    const T &GetAs(const string &name)
     629    {
     630        return *reinterpret_cast<S*>(fPointers[name]);
     631    }
     632
     633    void *SetPtrAddress(const string &name)
     634    {
     635        if (fTable.cols.count(name)==0)
     636        {
     637            ostringstream str;
     638            str <<"SetPtrAddress('" << name << "') - Column not found." << endl;
     639#ifdef __EXCEPTIONS
     640            throw runtime_error(str.str());
     641#else
     642            gLog << ___err___ << "ERROR - " << str.str() << endl;
     643            return NULL;
     644#endif
     645        }
     646
     647        fGarbage.push_back(vector<char>(fTable.cols[name].size*fTable.cols[name].num));
     648
     649        void *ptr = fGarbage.back().data();
     650
     651        fPointers[name] = ptr;
     652        fAddresses.push_back(make_pair(ptr, fTable.cols[name]));
     653        sort(fAddresses.begin(), fAddresses.end(), Compare);
     654        return ptr;
     655    }
     656
    616657    template<typename T>
    617658    bool SetPtrAddress(const string &name, T *ptr, size_t cnt)
     
    659700
    660701        //fAddresses[ptr] = fTable.cols[name];
     702        fPointers[name] = ptr;
    661703        fAddresses.push_back(make_pair(ptr, fTable.cols[name]));
    662704        sort(fAddresses.begin(), fAddresses.end(), Compare);
     
    706748
    707749        //fAddresses[ptr] = fTable.cols[name];
     750        fPointers[name] = ptr;
    708751        fAddresses.push_back(make_pair(ptr, fTable.cols[name]));
    709752        sort(fAddresses.begin(), fAddresses.end(), Compare);
     
    713756    bool     HasKey(const string &key) const { return fTable.HasKey(key); }
    714757    bool     HasColumn(const string& col) const { return fTable.HasColumn(col);}
    715     const Table::Columns &GetColumns() const { return fTable.getColumns();}
    716     const Table::Keys &GetKeys() const { return fTable.getKeys();}
     758    const Table::Columns &GetColumns() const { return fTable.GetColumns();}
     759    const Table::Keys &GetKeys() const { return fTable.GetKeys();}
    717760
    718761    int64_t  GetInt(const string &key) const { return fTable.Get<int64_t>(key); }
Note: See TracChangeset for help on using the changeset viewer.