• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()11 CPDF_Boolean::CPDF_Boolean() : m_bValue(false) {}
12 
CPDF_Boolean(bool value)13 CPDF_Boolean::CPDF_Boolean(bool value) : m_bValue(value) {}
14 
~CPDF_Boolean()15 CPDF_Boolean::~CPDF_Boolean() {}
16 
GetType() const17 CPDF_Object::Type CPDF_Boolean::GetType() const {
18   return BOOLEAN;
19 }
20 
Clone() const21 std::unique_ptr<CPDF_Object> CPDF_Boolean::Clone() const {
22   return pdfium::MakeUnique<CPDF_Boolean>(m_bValue);
23 }
24 
GetString() const25 ByteString CPDF_Boolean::GetString() const {
26   return m_bValue ? "true" : "false";
27 }
28 
GetInteger() const29 int CPDF_Boolean::GetInteger() const {
30   return m_bValue;
31 }
32 
SetString(const ByteString & str)33 void CPDF_Boolean::SetString(const ByteString& str) {
34   m_bValue = (str == "true");
35 }
36 
IsBoolean() const37 bool CPDF_Boolean::IsBoolean() const {
38   return true;
39 }
40 
AsBoolean()41 CPDF_Boolean* CPDF_Boolean::AsBoolean() {
42   return this;
43 }
44 
AsBoolean() const45 const CPDF_Boolean* CPDF_Boolean::AsBoolean() const {
46   return this;
47 }
48 
WriteTo(IFX_ArchiveStream * archive) const49 bool CPDF_Boolean::WriteTo(IFX_ArchiveStream* archive) const {
50   return archive->WriteString(" ") &&
51          archive->WriteString(GetString().AsStringView());
52 }
53