LCOV - code coverage report
Current view: top level - gfx/sfntly/cpp/src/sfntly/data - growable_memory_byte_array.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 28 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2011 Google Inc. All Rights Reserved.
       3             :  *
       4             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5             :  * you may not use this file except in compliance with the License.
       6             :  * You may obtain a copy of the License at
       7             :  *
       8             :  *      http://www.apache.org/licenses/LICENSE-2.0
       9             :  *
      10             :  * Unless required by applicable law or agreed to in writing, software
      11             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13             :  * See the License for the specific language governing permissions and
      14             :  * limitations under the License.
      15             :  */
      16             : 
      17             : #include "sfntly/data/growable_memory_byte_array.h"
      18             : 
      19             : #include <limits.h>
      20             : #include <string.h>
      21             : 
      22             : #include <algorithm>
      23             : 
      24             : namespace sfntly {
      25             : 
      26           0 : GrowableMemoryByteArray::GrowableMemoryByteArray()
      27           0 :     : ByteArray(0, INT_MAX, true) {
      28             :   // Note: We did not set an initial size of array like Java because STL
      29             :   //       implementation will determine the best strategy.
      30           0 : }
      31             : 
      32           0 : GrowableMemoryByteArray::~GrowableMemoryByteArray() {}
      33             : 
      34           0 : int32_t GrowableMemoryByteArray::CopyTo(OutputStream* os,
      35             :                                         int32_t offset,
      36             :                                         int32_t length) {
      37           0 :   assert(os);
      38           0 :   os->Write(&b_, offset, length);
      39           0 :   return length;
      40             : }
      41             : 
      42           0 : void GrowableMemoryByteArray::InternalPut(int32_t index, byte_t b) {
      43           0 :   if ((size_t)index >= b_.size()) {
      44           0 :     b_.resize((size_t)(index + 1));
      45             :   }
      46           0 :   b_[index] = b;
      47           0 : }
      48             : 
      49           0 : int32_t GrowableMemoryByteArray::InternalPut(int32_t index,
      50             :                                              byte_t* b,
      51             :                                              int32_t offset,
      52             :                                              int32_t length) {
      53           0 :   if ((size_t)index + length >= b_.size()) {
      54             :     // Note: We grow one byte more than Java version. VC debuggers shows
      55             :     //       data better this way.
      56           0 :     b_.resize((size_t)(index + length + 1));
      57             :   }
      58           0 :   std::copy(b + offset, b + offset + length, b_.begin() + index);
      59           0 :   return length;
      60             : }
      61             : 
      62           0 : byte_t GrowableMemoryByteArray::InternalGet(int32_t index) {
      63           0 :   return b_[index];
      64             : }
      65             : 
      66           0 : int32_t GrowableMemoryByteArray::InternalGet(int32_t index,
      67             :                                              byte_t* b,
      68             :                                              int32_t offset,
      69             :                                              int32_t length) {
      70           0 :   memcpy(b + offset, &(b_[0]) + index, length);
      71           0 :   return length;
      72             : }
      73             : 
      74           0 : void GrowableMemoryByteArray::Close() {
      75           0 :   b_.clear();
      76           0 : }
      77             : 
      78           0 : byte_t* GrowableMemoryByteArray::Begin() {
      79           0 :   return &(b_[0]);
      80             : }
      81             : 
      82             : }  // namespace sfntly

Generated by: LCOV version 1.13