1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "core/fpdfapi/parser/cpdf_boolean.h" 8 #include "core/fxcrt/fx_stream.h" 9 #include "third_party/base/ptr_util.h" 10 CPDF_Boolean()11CPDF_Boolean::CPDF_Boolean() : m_bValue(false) {} 12 CPDF_Boolean(bool value)13CPDF_Boolean::CPDF_Boolean(bool value) : m_bValue(value) {} 14 ~CPDF_Boolean()15CPDF_Boolean::~CPDF_Boolean() {} 16 GetType() const17CPDF_Object::Type CPDF_Boolean::GetType() const { 18 return BOOLEAN; 19 } 20 Clone() const21std::unique_ptr<CPDF_Object> CPDF_Boolean::Clone() const { 22 return pdfium::MakeUnique<CPDF_Boolean>(m_bValue); 23 } 24 GetString() const25ByteString CPDF_Boolean::GetString() const { 26 return m_bValue ? "true" : "false"; 27 } 28 GetInteger() const29int CPDF_Boolean::GetInteger() const { 30 return m_bValue; 31 } 32 SetString(const ByteString & str)33void CPDF_Boolean::SetString(const ByteString& str) { 34 m_bValue = (str == "true"); 35 } 36 IsBoolean() const37bool CPDF_Boolean::IsBoolean() const { 38 return true; 39 } 40 AsBoolean()41CPDF_Boolean* CPDF_Boolean::AsBoolean() { 42 return this; 43 } 44 AsBoolean() const45const CPDF_Boolean* CPDF_Boolean::AsBoolean() const { 46 return this; 47 } 48 WriteTo(IFX_ArchiveStream * archive) const49bool CPDF_Boolean::WriteTo(IFX_ArchiveStream* archive) const { 50 return archive->WriteString(" ") && 51 archive->WriteString(GetString().AsStringView()); 52 } 53