Back to index

tetex-bin  3.0
Public Member Functions | Private Attributes
ObjectStream Class Reference
Collaboration diagram for ObjectStream:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ObjectStream (XRef *xref, int objStrNumA)
 ~ObjectStream ()
int getObjStrNum ()
ObjectgetObject (int objIdx, int objNum, Object *obj)

Private Attributes

int objStrNum
int nObjects
Objectobjs
intobjNums

Detailed Description

Definition at line 53 of file XRef.cc.


Constructor & Destructor Documentation

ObjectStream::ObjectStream ( XRef xref,
int  objStrNumA 
)

Definition at line 77 of file XRef.cc.

                                                     {
  Stream *str;
  Parser *parser;
  int *offsets;
  Object objStr, obj1, obj2;
  int first, i;

  objStrNum = objStrNumA;
  nObjects = 0;
  objs = NULL;
  objNums = NULL;

  if (!xref->fetch(objStrNum, 0, &objStr)->isStream()) {
    goto err1;
  }

  if (!objStr.streamGetDict()->lookup("N", &obj1)->isInt()) {
    obj1.free();
    goto err1;
  }
  nObjects = obj1.getInt();
  obj1.free();
  if (nObjects <= 0) {
    goto err1;
  }

  if (!objStr.streamGetDict()->lookup("First", &obj1)->isInt()) {
    obj1.free();
    goto err1;
  }
  first = obj1.getInt();
  obj1.free();
  if (first < 0) {
    goto err1;
  }

  objs = new Object[nObjects];
  objNums = (int *)gmalloc(nObjects * sizeof(int));
  offsets = (int *)gmalloc(nObjects * sizeof(int));

  // parse the header: object numbers and offsets
  objStr.streamReset();
  obj1.initNull();
  str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
  parser = new Parser(xref, new Lexer(xref, str));
  for (i = 0; i < nObjects; ++i) {
    parser->getObj(&obj1);
    parser->getObj(&obj2);
    if (!obj1.isInt() || !obj2.isInt()) {
      obj1.free();
      obj2.free();
      delete parser;
      gfree(offsets);
      goto err1;
    }
    objNums[i] = obj1.getInt();
    offsets[i] = obj2.getInt();
    obj1.free();
    obj2.free();
    if (objNums[i] < 0 || offsets[i] < 0 ||
       (i > 0 && offsets[i] < offsets[i-1])) {
      delete parser;
      gfree(offsets);
      goto err1;
    }
  }
  while (str->getChar() != EOF) ;
  delete parser;

  // skip to the first object - this shouldn't be necessary because
  // the First key is supposed to be equal to offsets[0], but just in
  // case...
  for (i = first; i < offsets[0]; ++i) {
    objStr.getStream()->getChar();
  }

  // parse the objects
  for (i = 0; i < nObjects; ++i) {
    obj1.initNull();
    if (i == nObjects - 1) {
      str = new EmbedStream(objStr.getStream(), &obj1, gFalse, 0);
    } else {
      str = new EmbedStream(objStr.getStream(), &obj1, gTrue,
                         offsets[i+1] - offsets[i]);
    }
    parser = new Parser(xref, new Lexer(xref, str));
    parser->getObj(&objs[i]);
    while (str->getChar() != EOF) ;
    delete parser;
  }

  gfree(offsets);

 err1:
  objStr.free();
  return;
}

Here is the call graph for this function:

Definition at line 175 of file XRef.cc.

                            {
  int i;

  if (objs) {
    for (i = 0; i < nObjects; ++i) {
      objs[i].free();
    }
    delete[] objs;
  }
  gfree(objNums);
}

Here is the call graph for this function:


Member Function Documentation

Object * ObjectStream::getObject ( int  objIdx,
int  objNum,
Object obj 
)

Definition at line 187 of file XRef.cc.

                                                                   {
  if (objIdx < 0 || objIdx >= nObjects || objNum != objNums[objIdx]) {
    return obj->initNull();
  }
  return objs[objIdx].copy(obj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 63 of file XRef.cc.

{ return objStrNum; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 72 of file XRef.cc.

Definition at line 74 of file XRef.cc.

Definition at line 73 of file XRef.cc.

Definition at line 71 of file XRef.cc.


The documentation for this class was generated from the following file: