Commit 6296c289 authored by Albert Astals Cid's avatar Albert Astals Cid

Kill GooVector

std::vector does the same and GooVector is not part of xpdf so we don't
need to maintain it in case we ever get a new xpdf release we want to
merge with
parent 5934c320
......@@ -449,7 +449,6 @@ if(ENABLE_XPDF_HEADERS)
goo/GooTimer.h
goo/GooMutex.h
goo/GooString.h
goo/GooVector.h
goo/gtypes.h
goo/gmem.h
goo/gfile.h
......
//========================================================================
//
// GooVector.h
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 David Benjamin <davidben@mit.edu>
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
#ifndef GOO_GOOVECTOR_H
#define GOO_GOOVECTOR_H
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <new> // vector implementations need placement-new
#include <assert.h>
#include <stdlib.h>
/* Mostly STL-compatible vector class. Should correctly call constructors and
* destructors, but does not carefully handle alignment requirements. */
template<class T> class GooVector {
public:
/* various STL-compatible typedefs */
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef const T& const_reference;
typedef size_t size_type;
typedef int difference_type;
typedef T* iterator;
typedef const T* const_iterator;
// TODO: reverse_iterator, if we feel like it
GooVector() : m_data(NULL), m_capacity(0), m_size(0) {}
explicit GooVector(size_type n) : m_data(NULL), m_capacity(0), m_size(0) {
resize(n);
}
explicit GooVector(size_type n, const T& t) : m_data(NULL), m_capacity(0), m_size(0) {
resize(n, t);
}
explicit GooVector(const GooVector& gv) : m_data(NULL), m_capacity(0), m_size(0) {
reserve(gv.size());
for (size_type i = 0; i < m_size; i++) {
push_back(gv[i]);
}
}
~GooVector() {
clear();
}
iterator begin() { return m_data; }
const_iterator begin() const { return m_data; }
iterator end() { return m_data + m_size; }
const_iterator end() const { return m_data + m_size; }
size_type size() const { return m_size; }
size_type capacity() const { return m_capacity; }
bool empty() const { return m_size == 0; }
reference operator[] (size_type n) { return m_data[n]; }
const_reference operator[] (size_type n) const { return m_data[n]; }
reference at(size_type n) {
assert(n < m_size);
return m_data[n];
}
const_reference at(size_type n) const {
assert(n < m_size);
return m_data[n];
}
reference front() { assert(!empty()); return m_data[0]; }
const_reference front() const { assert(!empty()); return m_data[0]; }
reference back() { assert(!empty()); return m_data[m_size-1]; }
const_reference back() const { assert(!empty()); return m_data[m_size-1]; }
void push_back(const T& v) {
reserve(m_size + 1);
place_new(m_data + m_size, v);
m_size++;
}
void pop_back() {
assert(!empty());
m_size--;
destruct(m_data + m_size);
}
void clear() {
for (size_t i = 0; i < m_size; i++) {
destruct(m_data + i);
}
m_size = 0;
free(m_data);
m_data = NULL;
m_capacity = 0;
}
void reserve(size_type cap) {
if (m_capacity >= cap) return;
// make sure we always at least double
if (m_capacity*2 > cap)
cap = m_capacity*2;
resize_internal(cap);
}
void resize(size_type n) { resize(n, T()); }
void resize(size_type n, const T& t) {
reserve(n);
while (m_size < n)
push_back(t);
while (m_size > n)
pop_back();
}
private:
T *m_data;
size_type m_capacity;
size_type m_size;
inline void destruct(T *obj) {
obj->~T();
}
inline void place_new(T *loc, const T& v) {
new (loc) T(v);
}
inline void resize_internal(size_type new_cap) {
assert(new_cap >= m_capacity);
// To be correct with ctors and dtors, we do not use realloc and friends.
// A more efficient implementation would specialize for POD types and just
// realloc() or something. Meh, if we care, we ought to use just STL's
T *new_data = (T*) malloc(sizeof(T) * new_cap);
assert(new_data);
// Move over old data
if (m_data) {
for (size_type i = 0; i < m_size; i++) {
place_new(new_data + i, m_data[i]);
destruct(m_data + i);
}
free(m_data);
}
// And set the new values
m_data = new_data;
m_capacity = new_cap;
}
};
#endif
......@@ -9,7 +9,6 @@ poppler_goo_include_HEADERS = \
GooTimer.h \
GooMutex.h \
GooString.h \
GooVector.h \
gtypes.h \
gmem.h \
gfile.h \
......
......@@ -23,7 +23,7 @@ CachedFile::CachedFile(CachedFileLoader *cachedFileLoaderA, GooString *uriA)
loader = cachedFileLoaderA;
streamPos = 0;
chunks = new GooVector<Chunk>();
chunks = new std::vector<Chunk>();
length = 0;
length = loader->init(uri, this);
......@@ -70,15 +70,15 @@ int CachedFile::seek(long int offset, int origin)
return 0;
}
int CachedFile::cache(const GooVector<ByteRange> &origRanges)
int CachedFile::cache(const std::vector<ByteRange> &origRanges)
{
GooVector<int> loadChunks;
std::vector<int> loadChunks;
int numChunks = length/CachedFileChunkSize + 1;
GooVector<bool> chunkNeeded(numChunks);
std::vector<bool> chunkNeeded(numChunks);
int startChunk, endChunk;
GooVector<ByteRange> chunk_ranges, all;
std::vector<ByteRange> chunk_ranges, all;
ByteRange range;
const GooVector<ByteRange> *ranges = &origRanges;
const std::vector<ByteRange> *ranges = &origRanges;
if (ranges->empty()) {
range.offset = 0;
......@@ -87,7 +87,8 @@ int CachedFile::cache(const GooVector<ByteRange> &origRanges)
ranges = &all;
}
memset(&chunkNeeded[0], 0, sizeof(bool) * numChunks);
for (int i = 0; i < numChunks; ++i)
chunkNeeded[i] = false;
for (size_t i = 0; i < ranges->size(); i++) {
if ((*ranges)[i].length == 0) continue;
......@@ -166,7 +167,7 @@ size_t CachedFile::read(void *ptr, size_t unitsize, size_t count)
int CachedFile::cache(size_t offset, size_t length)
{
GooVector<ByteRange> r;
std::vector<ByteRange> r;
ByteRange range;
range.offset = offset;
range.length = length;
......@@ -178,7 +179,7 @@ int CachedFile::cache(size_t offset, size_t length)
// CachedFileWriter
//------------------------------------------------------------------------
CachedFileWriter::CachedFileWriter(CachedFile *cachedFileA, GooVector<int> *chunksA)
CachedFileWriter::CachedFileWriter(CachedFile *cachedFileA, std::vector<int> *chunksA)
{
cachedFile = cachedFileA;
chunks = chunksA;
......
......@@ -20,7 +20,8 @@
#include "goo/gtypes.h"
#include "Object.h"
#include "Stream.h"
#include "goo/GooVector.h"
#include <vector>
//------------------------------------------------------------------------
......@@ -51,7 +52,7 @@ public:
int seek(long int offset, int origin);
size_t read(void * ptr, size_t unitsize, size_t count);
size_t write(const char *ptr, size_t size, size_t fromByte);
int cache(const GooVector<ByteRange> &ranges);
int cache(const std::vector<ByteRange> &ranges);
// Reference counting.
void incRefCnt();
......@@ -79,7 +80,7 @@ private:
size_t length;
size_t streamPos;
GooVector<Chunk> *chunks;
std::vector<Chunk> *chunks;
int refCnt; // reference count
......@@ -99,7 +100,7 @@ public:
// Construct a CachedFile Writer.
// The caller is responsible for deleting the cachedFile and chunksA.
CachedFileWriter(CachedFile *cachedFile, GooVector<int> *chunksA);
CachedFileWriter(CachedFile *cachedFile, std::vector<int> *chunksA);
~CachedFileWriter();
......@@ -109,8 +110,8 @@ public:
private:
CachedFile *cachedFile;
GooVector<int> *chunks;
GooVector<int>::iterator it;
std::vector<int> *chunks;
std::vector<int>::iterator it;
size_t offset;
};
......@@ -136,7 +137,7 @@ public:
// Loads speficified byte ranges and passes it to the writer to store them.
// Returns 0 on success, Anything but 0 on failure.
// The caller is responsible for deleting the writer.
virtual int load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer) = 0;
virtual int load(const std::vector<ByteRange> &ranges, CachedFileWriter *writer) = 0;
};
......
......@@ -124,7 +124,7 @@ Catalog::Catalog(XRef *xrefA) {
Catalog::~Catalog() {
delete kidsIdxList;
if (attrsList) {
GooVector<PageAttrs *>::iterator it;
std::vector<PageAttrs *>::iterator it;
for (it = attrsList->begin() ; it < attrsList->end(); it++ ) {
delete *it;
}
......@@ -132,7 +132,7 @@ Catalog::~Catalog() {
}
delete pagesRefList;
if (pagesList) {
GooVector<Dict *>::iterator it;
std::vector<Dict *>::iterator it;
for (it = pagesList->begin() ; it < pagesList->end(); it++ ) {
if (!(*it)->decRef()) {
delete *it;
......@@ -267,13 +267,13 @@ GBool Catalog::cachePageTree(int page)
pageRefs[i].gen = -1;
}
pagesList = new GooVector<Dict *>();
pagesList = new std::vector<Dict *>();
pagesList->push_back(pagesDict);
pagesRefList = new GooVector<Ref>();
pagesRefList = new std::vector<Ref>();
pagesRefList->push_back(pagesRef);
attrsList = new GooVector<PageAttrs *>();
attrsList = new std::vector<PageAttrs *>();
attrsList->push_back(new PageAttrs(NULL, pagesDict));
kidsIdxList = new GooVector<int>();
kidsIdxList = new std::vector<int>();
kidsIdxList->push_back(0);
lastCachedPage = 0;
......
......@@ -33,6 +33,8 @@
#pragma interface
#endif
#include <vector>
class XRef;
class Object;
class Page;
......@@ -233,10 +235,10 @@ private:
Page **pages; // array of pages
Ref *pageRefs; // object ID for each page
int lastCachedPage;
GooVector<Dict *> *pagesList;
GooVector<Ref> *pagesRefList;
GooVector<PageAttrs *> *attrsList;
GooVector<int> *kidsIdxList;
std::vector<Dict *> *pagesList;
std::vector<Ref> *pagesRefList;
std::vector<PageAttrs *> *attrsList;
std::vector<int> *kidsIdxList;
Form *form;
int numPages; // number of pages
int pagesSize; // size of pages array
......
......@@ -6,7 +6,7 @@
//
// Copyright 2006 Julien Rebetez <julienr@svn.gnome.org>
// Copyright 2007, 2008 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright 2007-2009 Albert Astals Cid <aacid@kde.org>
// Copyright 2007-2010 Albert Astals Cid <aacid@kde.org>
// Copyright 2010 Mark Riedesel <mark@klowner.com>
//
//========================================================================
......@@ -19,7 +19,6 @@
#endif
#include "Object.h"
#include "goo/GooVector.h"
class GooString;
class Array;
......
......@@ -17,7 +17,7 @@
// Copyright (C) 2007 Iñigo Martínez <inigomartinez@gmail.com>
// Copyright (C) 2008 Brad Hards <bradh@kde.org>
// Copyright (C) 2008, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009, 2010 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009, 2010 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2010 David Benjamin <davidben@mit.edu>
// Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
......@@ -36,11 +36,12 @@
#include "goo/gtypes.h"
#include "goo/GooList.h"
#include "goo/GooVector.h"
#include "GfxState.h"
#include "Object.h"
#include "PopplerCache.h"
#include <vector>
class GooString;
class XRef;
class Array;
......@@ -202,7 +203,7 @@ private:
GfxState *state; // current graphics state
int stackHeight; // the height of the current graphics stack
GooVector<int> stateGuards; // a stack of state limits; to guard against unmatched pops
std::vector<int> stateGuards; // a stack of state limits; to guard against unmatched pops
GBool fontChanged; // set if font or text matrix has changed
GfxClipType clip; // do a clip?
int ignoreUndef; // current BX/EX nesting level
......
......@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
......@@ -351,7 +352,7 @@ Guint Hints::getPageOffset(int page)
return pageOffset[0];
}
GooVector<ByteRange>* Hints::getPageRanges(int page)
std::vector<ByteRange>* Hints::getPageRanges(int page)
{
if ((page < 1) || (page > nPages)) return NULL;
......@@ -364,7 +365,7 @@ GooVector<ByteRange>* Hints::getPageRanges(int page)
idx = 0;
ByteRange pageRange;
GooVector<ByteRange> *v = new GooVector<ByteRange>;
std::vector<ByteRange> *v = new std::vector<ByteRange>;
pageRange.offset = pageOffset[idx];
pageRange.length = pageLength[idx];
......
......@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
......@@ -13,8 +14,7 @@
#include <string.h>
#include "goo/gtypes.h"
#include "goo/GooVector.h"
//#include <vector>
#include <vector>
#include "PDFDoc.h"
class Stream;
......@@ -34,7 +34,7 @@ public:
int getPageObjectNum(int page);
Guint getPageOffset(int page);
GooVector<ByteRange>* getPageRanges(int page);
std::vector<ByteRange>* getPageRanges(int page);
private:
......
......@@ -40,7 +40,7 @@ size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile)
return size;
}
int StdinCacheLoader::load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer)
int StdinCacheLoader::load(const std::vector<ByteRange> &ranges, CachedFileWriter *writer)
{
return 0;
}
......
......@@ -19,7 +19,7 @@ class StdinCacheLoader : public CachedFileLoader {
public:
size_t init(GooString *dummy, CachedFile* cachedFile);
int load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer);
int load(const std::vector<ByteRange> &ranges, CachedFileWriter *writer);
};
......
......@@ -34,7 +34,6 @@
#include <stdio.h>
#include "goo/gtypes.h"
#include "goo/GooVector.h"
#include "Object.h"
class BaseStream;
......
......@@ -303,7 +303,7 @@ XRef::XRef(BaseStream *strA, Guint pos, Guint mainXRefEntriesOffsetA, GBool *was
// read the xref table
} else {
GooVector<Guint> followedXRefStm;
std::vector<Guint> followedXRefStm;
readXRef(&prevXRefOffset, &followedXRefStm);
// if there was a problem with the xref table,
......@@ -419,7 +419,7 @@ int XRef::resize(int newSize)
// Read one xref table section. Also reads the associated trailer
// dictionary, and returns the prev pointer (if any).
GBool XRef::readXRef(Guint *pos, GooVector<Guint> *followedXRefStm) {
GBool XRef::readXRef(Guint *pos, std::vector<Guint> *followedXRefStm) {
Parser *parser;
Object obj;
GBool more;
......@@ -471,7 +471,7 @@ GBool XRef::readXRef(Guint *pos, GooVector<Guint> *followedXRefStm) {
return gFalse;
}
GBool XRef::readXRefTable(Parser *parser, Guint *pos, GooVector<Guint> *followedXRefStm) {
GBool XRef::readXRefTable(Parser *parser, Guint *pos, std::vector<Guint> *followedXRefStm) {
XRefEntry entry;
GBool more;
Object obj, obj2;
......@@ -1282,7 +1282,7 @@ XRefEntry *XRef::getEntry(int i)
error(-1, "Failed to parse XRef entry [%d].", i);
}
} else {
GooVector<Guint> followedPrev;
std::vector<Guint> followedPrev;
while (prevXRefOffset && entries[i].type == xrefEntryNone) {
bool followed = false;
for (size_t j = 0; j < followedPrev.size(); j++) {
......@@ -1301,7 +1301,7 @@ XRefEntry *XRef::getEntry(int i)
followedPrev.push_back (prevXRefOffset);
GooVector<Guint> followedXRefStm;
std::vector<Guint> followedXRefStm;
if (!readXRef(&prevXRefOffset, &followedXRefStm)) {
prevXRefOffset = 0;
}
......
......@@ -33,9 +33,10 @@
#endif
#include "goo/gtypes.h"
#include "goo/GooVector.h"
#include "Object.h"
#include <vector>
class Dict;
class Stream;
class Parser;
......@@ -163,8 +164,8 @@ private:
int reserve(int newSize);
int resize(int newSize);
Guint getStartXref();
GBool readXRef(Guint *pos, GooVector<Guint> *followedXRefStm);
GBool readXRefTable(Parser *parser, Guint *pos, GooVector<Guint> *followedXRefStm);
GBool readXRef(Guint *pos, std::vector<Guint> *followedXRefStm);
GBool readXRefTable(Parser *parser, Guint *pos, std::vector<Guint> *followedXRefStm);
GBool readXRefStreamSection(Stream *xrefStr, int *w, int first, int n);
GBool readXRefStream(Stream *xrefStr, Guint *pos);
GBool constructXRef(GBool *wasReconstructed);
......
......@@ -17,7 +17,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
// Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2007, 2010 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2008 Boris Toloknov <tlknv@yandex.ru>
// Copyright (C) 2008 Tomas Are Haavet <tomasare@gmail.com>
// Copyright (C) 2010 OSSD CDAC Mumbai by Leena Chourey (leenac@cdacmumbai.in) and Onkar Potdar (onkar@cdacmumbai.in)
......@@ -267,7 +267,7 @@ GooString* HtmlFont::simple(HtmlFont* font, Unicode* content, int uLen){
}
HtmlFontAccu::HtmlFontAccu(){
accu=new GooVector<HtmlFont>();
accu=new std::vector<HtmlFont>();
}
HtmlFontAccu::~HtmlFontAccu(){
......@@ -275,7 +275,7 @@ HtmlFontAccu::~HtmlFontAccu(){
}
int HtmlFontAccu::AddFont(const HtmlFont& font){
GooVector<HtmlFont>::iterator i;
std::vector<HtmlFont>::iterator i;
for (i=accu->begin();i!=accu->end();i++)
{
if (font.isEqual(*i))
......@@ -317,7 +317,7 @@ GooString* HtmlFontAccu::CSStyle(int i, int j){
GooString *iStr=GooString::fromInt(i);
GooString *jStr=GooString::fromInt(j);
GooVector<HtmlFont>::iterator g=accu->begin();
std::vector<HtmlFont>::iterator g=accu->begin();
g+=i;
HtmlFont font=*g;
GooString *Size=GooString::fromInt(font.getSize());
......
......@@ -18,6 +18,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2010 OSSD CDAC Mumbai by Leena Chourey (leenac@cdacmumbai.in) and Onkar Potdar (onkar@cdacmumbai.in)
// Copyright (C) 2010 Albert Astals Cid <aacid@kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -26,11 +27,10 @@
#ifndef _HTML_FONTS_H
#define _HTML_FONTS_H
#include "goo/GooVector.h"
#include "goo/GooString.h"
#include "GfxState.h"
#include "CharTypes.h"
#include <vector>
class HtmlFontColor{
private:
......@@ -92,16 +92,14 @@ public:
class HtmlFontAccu{
private:
GooVector<HtmlFont> *accu;
std::vector<HtmlFont> *accu;
public:
HtmlFontAccu();
~HtmlFontAccu();
int AddFont(const HtmlFont& font);
HtmlFont* Get(int i){
GooVector<HtmlFont>::iterator g=accu->begin();
g+=i;
return g;
HtmlFont *Get(int i){
return &(*accu)[i];
}
GooString* getCSStyle (int i,GooString* content, int j = 0);
GooString* CSStyle(int i, int j = 0);
......
......@@ -118,7 +118,7 @@ GooString* HtmlLink::getLinkStart() {
HtmlLinks::HtmlLinks(){
accu=new GooVector<HtmlLink>();
accu=new std::vector<HtmlLink>();
}
HtmlLinks::~HtmlLinks(){
......@@ -128,7 +128,7 @@ HtmlLinks::~HtmlLinks(){
GBool HtmlLinks::inLink(double xmin,double ymin,double xmax,double ymax,int& p)const {
for(GooVector<HtmlLink>::iterator i=accu->begin();i!=accu->end();i++){
for(std::vector<HtmlLink>::iterator i=accu->begin();i!=accu->end();i++){
if (i->inLink(xmin,ymin,xmax,ymax)) {
p=(i - accu->begin());
return 1;
......@@ -138,8 +138,6 @@ GBool HtmlLinks::inLink(double xmin,double ymin,double xmax,double ymax,int& p)c
}
HtmlLink* HtmlLinks::getLink(int i) const{
GooVector<HtmlLink>::iterator g=accu->begin();
g+=i;
return g;
return &(*accu)[i];
}
......@@ -29,7 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include "goo/GooVector.h"
#include <vector>
#include "goo/GooString.h"
class HtmlLink{
......@@ -59,7 +59,7 @@ public:
class HtmlLinks{
private:
GooVector<HtmlLink> *accu;
std::vector<HtmlLink> *accu;
public:
HtmlLinks();
~HtmlLinks();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment