Skip to content

Commit

Permalink
[UPDATE] Bit parsing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gaganjyot committed Jan 18, 2015
1 parent 679e313 commit c343db8
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/dwgentities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#include "dwgentities.h"

void Line::ParseLine(char*) {
bool Line::ParseLine() {

}
2 changes: 2 additions & 0 deletions src/dwgentities.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Line : public TE {
void setStart(Point_2D_t s) { start_ = s; }
void setEnd(Point_2D_t e) { end_ = e; }

bool ParseLine();

};

class Circle : public TE {
Expand Down
1 change: 1 addition & 0 deletions src/dwgparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

dwgparser::dwgparser(const char *)
{

}

void dwgparser::ReadEntities(char *) {
Expand Down
2 changes: 1 addition & 1 deletion src/dwgparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

class dwgparser {
public:
dwgparser(const char*);
dwgparser(const char *);
void ReadEntities(char *);

};
80 changes: 67 additions & 13 deletions src/dwgreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,80 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "dwgreader.h"

uint8_t DWG_Reader::Read_Bit() {
auto buff = data[byte];

#include <stdio.h>
#define dbgn(x) std::cout << x << "\n";
#define dbgt(x) std::cout << x << "\t";
#define pfdn(val) std::printf("%d\n", val);
#define pfdt(val) std::printf("%d\t", val);
#define bpos(x) \
if (x==0) std::cout << "Bitpos is : " << 0 << "\n"; \
else if (x==1) std::cout << "Bitpos is : " << 1 << "\n"; \
else if (x==2) std::cout << "Bitpos is : " << 2 << "\n"; \
else if (x==3) std::cout << "Bitpos is : " << 3 << "\n"; \
else if (x==4) std::cout << "Bitpos is : " << 4 << "\n"; \
else if (x==5) std::cout << "Bitpos is : " << 5 << "\n"; \
else if (x==6) std::cout << "Bitpos is : " << 6 << "\n"; \
else if (x==7) std::cout << "Bitpos is : " << 7 << "\n"; \
else if (x==8) std::cout << "Bitpos is : " << 8 << "\n"; \
else std::cout << "Error\n";


DWG_Reader::DWG_Reader(std::ifstream *str) {
str->seekg (0, std::ios_base::end);
strsize = str->tellg();
str->seekg(0, std::ios_base::beg);
u_int32_t i = 0;
char tmp;
while(strsize>=i) {
str->read(&tmp, 1);
s.push_back(tmp);
i++;
}

// for (int i = 0; i < 8; i++) {
// dbgt(i) pfd(Read_Bit())
// }
// dbg("\n")
// for (int i = 0; i < 8; i++) {
// dbgt(i) pfd(Read_Bit())
// }
// Read_3Bits();
}

uint8_t DWG_Reader::Read_2Bits() {

u_int8_t DWG_Reader::Read_Bit() {
char tmpbyte = s[bytepos];
u_int8_t val = (tmpbyte >> (7 - bitpos)) & 1;
bitpos++;
if(8 == bitpos) {
bitpos = 0;
bytepos++;
}
return val;
}

uint8_t DWG_Reader::Read_3Bits() {
u_int8_t DWG_Reader::Read_2Bits() {
char tmpbyte = s[bytepos];
u_int8_t val;
if(7 > bitpos) {
val = (tmpbyte >> (6 - bitpos)) & 3;
} else {
u_int8_t t = Read_Bit();
val = Read_Bit() | (t << 1);
}
return val;
}

u_int8_t DWG_Reader::Read_3Bits() {
if(0==Read_Bit()) return 0;
if(0==Read_Bit()) return 1;
if(0==Read_Bit()) return 3;
return 7;
}

int16_t DWG_Reader::Read_BitShort() {

}

int32_t DWG_Reader::Read_BitLong() {

}

int64_t DWG_Reader::Read_BitLongLong() {
Expand All @@ -50,23 +104,23 @@ double DWG_Reader::Read_Double() {

}

uint8_t DWG_Reader::Read_RawChar() {
u_int8_t DWG_Reader::Read_RawChar() {

}

uint16_t DWG_Reader::Read_RawShort() {
u_int16_t DWG_Reader::Read_RawShort() {

}

double DWG_Reader::Read_RawDouble() {

}

uint32_t DWG_Reader::Read_RawLong() {
u_int32_t DWG_Reader::Read_RawLong() {

}

uint64_t DWG_Reader::Read_RawLongLong() {
u_int64_t DWG_Reader::Read_RawLongLong() {

}

Expand Down
29 changes: 16 additions & 13 deletions src/dwgreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <iostream>
#include <sstream>
#include <fstream>
#include <memory>
#include <vector>
class DWG_Reader {

public:
DWG_Reader() { }
uint8_t Read_Bit();
uint8_t Read_2Bits();
uint8_t Read_3Bits();
DWG_Reader(std::ifstream *);
u_int8_t Read_Bit();
u_int8_t Read_2Bits();
u_int8_t Read_3Bits();
int16_t Read_BitShort();
int32_t Read_BitLong();
int64_t Read_BitLongLong();
int64_t Read_BitLongLong();
double Read_Double();
uint8_t Read_RawChar();
uint16_t Read_RawShort();
u_int8_t Read_RawChar();
u_int16_t Read_RawShort();
double Read_RawDouble();
uint32_t Read_RawLong();
uint64_t Read_RawLongLong();
u_int32_t Read_RawLong();
u_int64_t Read_RawLongLong();
Point_3D_t Read_Extrusion(bool v);
double Read_Thickness(bool v);
color_t Read_Color(bool v);

private:
uint8_t* data;
uint32_t byte = 0;
uint8_t bit = 0;
DWG_Version version;
std::vector<char> s;
u_int32_t strsize;
u_int32_t bytepos = 0;
u_int8_t bitpos = 0;
DWG_Version version;
};
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <iostream>
#include "dwgreader.h"

using namespace std;

int main()
{
ifstream x;
x.open("/home/gagan/stuff/example.dwg", std::ios_base::in | std::ios_base::binary);
DWG_Reader A(&x);
cout << "Hello World!" << endl;
return 0;
}

0 comments on commit c343db8

Please sign in to comment.