"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.60/prc/PRCbitStream.h" (6 Nov 2019, 2518 Bytes) of package /linux/misc/asymptote-2.60.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PRCbitStream.h" see the Fossies "Dox" file reference documentation.

    1 /************
    2 *
    3 *   This file is part of a tool for producing 3D content in the PRC format.
    4 *   Copyright (C) 2008  Orest Shardt <shardtor (at) gmail dot com> and
    5 *                       Michail Vidiassov <master@iaas.msu.ru>
    6 *
    7 *   This program is free software: you can redistribute it and/or modify
    8 *   it under the terms of the GNU Lesser General Public License as published by
    9 *   the Free Software Foundation, either version 3 of the License, or
   10 *   (at your option) any later version.
   11 *
   12 *   This program is distributed in the hope that it will be useful,
   13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15 *   GNU Lesser General Public License for more details.
   16 *
   17 *   You should have received a copy of the GNU Lesser General Public License
   18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   19 *
   20 *************/
   21 
   22 #ifndef __PRC_BIT_STREAM_H
   23 #define __PRC_BIT_STREAM_H
   24 
   25 #ifdef _MSC_VER
   26 #include <stdio.h>
   27 #if _MSC_VER >= 1600
   28 #include <stdint.h>
   29 #else
   30 typedef signed char int8_t;
   31 typedef signed short int16_t;
   32 typedef signed long int32_t;
   33 typedef unsigned char uint8_t;
   34 typedef unsigned short uint16_t;
   35 typedef unsigned long uint32_t;
   36 #endif // _MSC_VER >= 1600
   37 #else
   38 #include <inttypes.h>
   39 #endif // _MSC_VER
   40 #include <string>
   41 #include <iostream>
   42 #include <stdlib.h>
   43 
   44 #define CHUNK_SIZE (1024)
   45 // Is this a reasonable initial size?
   46 
   47 class PRCbitStream
   48 {
   49   public:
   50     PRCbitStream(uint8_t*& buff, unsigned int l) : byteIndex(0), bitIndex(0),
   51                  allocatedLength(l), data(buff), compressed(false)
   52     {
   53       if(data == 0)
   54       {
   55         getAChunk();
   56       }
   57     }
   58 
   59     unsigned int getSize() const;
   60     uint8_t* getData();
   61 
   62     PRCbitStream& operator <<(const std::string&);
   63     PRCbitStream& operator <<(bool);
   64     PRCbitStream& operator <<(uint32_t);
   65     PRCbitStream& operator <<(uint8_t);
   66     PRCbitStream& operator <<(int32_t);
   67     PRCbitStream& operator <<(double);
   68     PRCbitStream& operator <<(const char*);
   69 
   70     void compress();
   71     void write(std::ostream &out) const;
   72   private:
   73     void writeBit(bool);
   74     void writeBits(uint32_t,uint8_t);
   75     void writeByte(uint8_t);
   76     void nextByte();
   77     void nextBit();
   78     void getAChunk();
   79     // bitIndex is "big endian", zero based, location of next bit to write
   80     unsigned int byteIndex,bitIndex;
   81     unsigned int allocatedLength;
   82     uint8_t*& data;
   83     bool compressed;
   84     uint32_t compressedDataSize;
   85 };
   86 
   87 #endif // __PRC_BIT_STREAM_H