"Fossies" - the Fresh Open Source Software Archive

Member "poppler-0.82.0/poppler/Array.cc" (25 Oct 2019, 2898 Bytes) of package /linux/misc/poppler-0.82.0.tar.xz:


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 "Array.cc" see the Fossies "Dox" file reference documentation.

    1 //========================================================================
    2 //
    3 // Array.cc
    4 //
    5 // Copyright 1996-2003 Glyph & Cog, LLC
    6 //
    7 //========================================================================
    8 
    9 //========================================================================
   10 //
   11 // Modified under the Poppler project - http://poppler.freedesktop.org
   12 //
   13 // All changes made under the Poppler project to this file are licensed
   14 // under GPL version 2 or later
   15 //
   16 // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
   17 // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
   18 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
   19 // Copyright (C) 2013, 2017, 2019 Albert Astals Cid <aacid@kde.org>
   20 // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
   21 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
   22 //
   23 // To see a description of the changes please see the Changelog file that
   24 // came with your tarball or type make ChangeLog if you are building from git
   25 //
   26 //========================================================================
   27 
   28 #include <config.h>
   29 
   30 #include <cassert>
   31 
   32 #include "Object.h"
   33 #include "Array.h"
   34 
   35 //------------------------------------------------------------------------
   36 // Array
   37 //------------------------------------------------------------------------
   38 
   39 #define arrayLocker()   std::unique_lock<std::recursive_mutex> locker(mutex)
   40 
   41 Array::Array(XRef *xrefA) {
   42   xref = xrefA;
   43   ref = 1;
   44 }
   45 
   46 Array::~Array() {
   47 }
   48 
   49 Object Array::copy(XRef *xrefA) const {
   50   arrayLocker();
   51   Array *a = new Array(xrefA);
   52   a->elems.reserve(elems.size());
   53   for (const auto& elem : elems) {
   54     a->elems.push_back(elem.copy());
   55   }
   56   return Object(a);
   57 }
   58 
   59 void Array::add(Object &&elem) {
   60   arrayLocker();
   61   elems.push_back(std::move(elem));
   62 }
   63 
   64 void Array::remove(int i) {
   65   arrayLocker();
   66   if (i < 0 || std::size_t(i) >= elems.size()) {
   67     assert(i >= 0 && std::size_t(i) < elems.size());
   68     return;
   69   }
   70   elems.erase(elems.begin() + i);
   71 }
   72 
   73 Object Array::get(int i, int recursion) const {
   74   if (i < 0 || std::size_t(i) >= elems.size()) {
   75     return Object(objNull);
   76   }
   77   return elems[i].fetch(xref, recursion);
   78 }
   79 
   80 Object Array::get(int i, Ref *returnRef, int recursion) const
   81 {
   82   if (i < 0 || std::size_t(i) >= elems.size()) {
   83     *returnRef = Ref::INVALID();
   84     return Object(objNull);
   85   }
   86   if (elems[i].getType() == objRef) {
   87     *returnRef = elems[i].getRef();
   88   } else {
   89     *returnRef = Ref::INVALID();
   90   }
   91   return elems[i].fetch(xref, recursion);
   92 }
   93 
   94 const Object &Array::getNF(int i) const {
   95   if (i < 0 || std::size_t(i) >= elems.size()) {
   96     static Object nullObj(objNull);
   97     return nullObj;
   98   }
   99   return elems[i];
  100 }
  101 
  102 bool Array::getString(int i, GooString *string) const
  103 {
  104   const Object &obj = getNF(i);
  105   if (obj.isString()) {
  106     string->clear();
  107     string->append(obj.getString());
  108     return true;
  109   } else {
  110     return false;
  111   }
  112 }