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 #ifndef CORE_FPDFAPI_PARSER_CPDF_NUMBER_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_NUMBER_H_ 9 10 #include <memory> 11 12 #include "core/fpdfapi/parser/cpdf_object.h" 13 #include "core/fxcrt/fx_string.h" 14 #include "core/fxcrt/fx_system.h" 15 16 class CPDF_Number : public CPDF_Object { 17 public: 18 CPDF_Number(); 19 explicit CPDF_Number(int value); 20 explicit CPDF_Number(float value); 21 explicit CPDF_Number(const ByteStringView& str); 22 ~CPDF_Number() override; 23 24 // CPDF_Object: 25 Type GetType() const override; 26 std::unique_ptr<CPDF_Object> Clone() const override; 27 ByteString GetString() const override; 28 float GetNumber() const override; 29 int GetInteger() const override; 30 void SetString(const ByteString& str) override; 31 bool IsNumber() const override; 32 CPDF_Number* AsNumber() override; 33 const CPDF_Number* AsNumber() const override; 34 bool WriteTo(IFX_ArchiveStream* archive) const override; 35 IsInteger()36 bool IsInteger() const { return m_bInteger; } 37 38 protected: 39 bool m_bInteger; 40 union { 41 int m_Integer; 42 float m_Float; 43 }; 44 }; 45 ToNumber(CPDF_Object * obj)46inline CPDF_Number* ToNumber(CPDF_Object* obj) { 47 return obj ? obj->AsNumber() : nullptr; 48 } 49 ToNumber(const CPDF_Object * obj)50inline const CPDF_Number* ToNumber(const CPDF_Object* obj) { 51 return obj ? obj->AsNumber() : nullptr; 52 } 53 54 #endif // CORE_FPDFAPI_PARSER_CPDF_NUMBER_H_ 55