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(FX_FLOAT value); 21 explicit CPDF_Number(const CFX_ByteStringC& str); 22 ~CPDF_Number() override; 23 24 // CPDF_Object: 25 Type GetType() const override; 26 std::unique_ptr<CPDF_Object> Clone() const override; 27 CFX_ByteString GetString() const override; 28 FX_FLOAT GetNumber() const override; 29 int GetInteger() const override; 30 void SetString(const CFX_ByteString& str) override; 31 bool IsNumber() const override; 32 CPDF_Number* AsNumber() override; 33 const CPDF_Number* AsNumber() const override; 34 IsInteger()35 bool IsInteger() const { return m_bInteger; } 36 37 protected: 38 bool m_bInteger; 39 union { 40 int m_Integer; 41 FX_FLOAT m_Float; 42 }; 43 }; 44 ToNumber(CPDF_Object * obj)45inline CPDF_Number* ToNumber(CPDF_Object* obj) { 46 return obj ? obj->AsNumber() : nullptr; 47 } 48 ToNumber(const CPDF_Object * obj)49inline const CPDF_Number* ToNumber(const CPDF_Object* obj) { 50 return obj ? obj->AsNumber() : nullptr; 51 } 52 53 #endif // CORE_FPDFAPI_PARSER_CPDF_NUMBER_H_ 54