OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkValue_DEFINED |
| 9 #define SkValue_DEFINED |
| 10 |
| 11 #include "SkTypes.h" |
| 12 #include <functional> |
| 13 |
| 14 class SkValue { |
| 15 public: |
| 16 enum Type : uint32_t { |
| 17 // 0-255 are reserved for built-in SkValue types. |
| 18 Null, |
| 19 Byte , S16 , U16 , S32 , U32 , S64 , U64 , F32 , F64 , |
| 20 Bytes, S16s, U16s, S32s, U32s, S64s, U64s, F32s, F64s, |
| 21 Array, |
| 22 |
| 23 // 256-2147483647 may be used by Skia for public Object types. |
| 24 |
| 25 |
| 26 // 2147483648+ won't be used by Skia. They're open for client-specific
use, testing, etc. |
| 27 }; |
| 28 |
| 29 enum Key : uint32_t { |
| 30 // Each Object type may define its own namespace of Key values, |
| 31 // so there are no pre-defined Keys here. |
| 32 // |
| 33 // This is just a reminder that they must fit in a uint32_t, |
| 34 // and that their namespace is distinct from other uint32_ts (e.g. Type)
. |
| 35 }; |
| 36 |
| 37 SkValue(); |
| 38 SkValue(const SkValue&); |
| 39 SkValue(SkValue&&); |
| 40 |
| 41 SkValue& operator=(const SkValue&); |
| 42 SkValue& operator=(SkValue&&); |
| 43 |
| 44 ~SkValue(); |
| 45 |
| 46 static SkValue FromS32(int32_t); |
| 47 static SkValue FromU32(uint32_t); |
| 48 static SkValue FromF32(float); |
| 49 static SkValue FromBytes(const void*, size_t); // Copies. |
| 50 static SkValue Object(Type); |
| 51 |
| 52 Type type() const; |
| 53 |
| 54 // These remaining methods may assert they're called on a value of the appro
priate type. |
| 55 |
| 56 int32_t s32() const; |
| 57 uint32_t u32() const; |
| 58 float f32() const; |
| 59 |
| 60 const void* bytes() const; |
| 61 size_t count() const; |
| 62 |
| 63 void set(Key, SkValue); |
| 64 const SkValue* get(Key) const; |
| 65 void foreach(std::function<void(Key, const SkValue&)>) const; |
| 66 |
| 67 private: |
| 68 class Bytes; |
| 69 class Object; |
| 70 |
| 71 Type fType; |
| 72 union { |
| 73 int32_t fS32; |
| 74 uint32_t fU32; |
| 75 float fF32; |
| 76 class Bytes* fBytes; |
| 77 class Object* fObject; |
| 78 }; |
| 79 }; |
| 80 |
| 81 #endif//SkValue_DEFINED |
OLD | NEW |