Changeset 17223


Ignore:
Timestamp:
10/16/13 19:17:30 (11 years ago)
Author:
tbretz
Message:
Renamed BlockHeaderWriter to Compression - it is the user interface! Renamed member functions to something more reasonable; added correct types so that enums can be casted in the call to AddColumn
File:
1 edited

Legend:

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

    r17222 r17223  
    6868
    6969    //Helper structure to simplify the initialization and handling of compressed blocks headers
    70     struct BlockHeaderWriter
     70    struct Compression
    7171    {
    72         BlockHeaderWriter(const std::string& comp="") : header(),
    73                                                         sequence()
     72        BlockHeader header;
     73        std::vector<uint16_t> sequence;
     74
     75        Compression(const std::vector<uint16_t> &seq, const RowOrdering_t &order=kOrderByCol)
     76            : header(0, order, seq.size()), sequence(seq)
    7477        {
    75             if (comp == "" || comp == "RAW")
    76             {
    77                 sequence.emplace_back(kFactRaw);
    78                 return;
    79             }
    80             if (comp == "SMOOTHMAN")
    81             {
    82                 header = BlockHeader(0, kOrderByRow, 2);
    83                 sequence.emplace_back(kFactSmoothing);
    84                 sequence.emplace_back(kFactHuffman16);
    85                 return;
    86             }
    8778
    88             std::ostringstream str;
    89             str << "Unkown compression requested: " << comp;
    90 #ifdef __EXCEPTIONS
    91             throw std::runtime_error(str.str());
    92 #else
    93             gLog << ___err___ << "ERROR - " << str.str();
    94             return;
    95 #endif
    9679        }
    9780
    98         void Write(char* to)
     81        Compression(const CompressionProcess_t &compression=kFactRaw, const RowOrdering_t &order=kOrderByCol)
     82            : header(0, order, 1), sequence(1)
    9983        {
    100             memcpy(to, &header, sizeof(BlockHeader));
    101             memcpy(to+sizeof(BlockHeader), sequence.data(), header.numProcs*sizeof(uint16_t));
     84            sequence[0] = compression;
    10285        }
    10386
    104         uint32_t SizeOnDisk() { return sizeof(BlockHeader) + sizeof(uint16_t)*header.numProcs;}
     87        RowOrdering_t getOrdering() const { return RowOrdering_t(header.ordering); }
     88        uint32_t getSizeOnDisk() const { return sizeof(BlockHeader) + sizeof(uint16_t)*header.numProcs; }
     89        CompressionProcess_t getProc(uint32_t i) const { return CompressionProcess_t(sequence[i]); }
     90        uint16_t getNumProcs() const { return header.numProcs; }
    10591
    106         uint16_t Proc(uint32_t i) { return sequence[i]; }
     92        void SetBlockSize(uint64_t size) { header.size = size; }
     93        void Memcpy(char *dest) const
     94        {
     95            memcpy(dest, &header, sizeof(BlockHeader));
     96            memcpy(dest+sizeof(BlockHeader), sequence.data(), header.numProcs*sizeof(uint16_t));
     97        }
    10798
    108         uint16_t NumProcs() { return header.numProcs; }
    10999
    110         char Ordering() { return header.ordering;}
     100    };
    111101
    112         void SetBlockSize(uint64_t size) { header.size = size;}
    113 
    114         BlockHeader      header;
    115         std::vector<uint16_t> sequence;
    116     };
    117102
    118103#endif
Note: See TracChangeset for help on using the changeset viewer.