| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> | 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> |
| 3 * Copyright (C) 2006 Apple Computer, Inc. | 3 * Copyright (C) 2006 Apple Computer, Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef XPathValue_h | 27 #ifndef XPathValue_h |
| 28 #define XPathValue_h | 28 #define XPathValue_h |
| 29 | 29 |
| 30 #include "core/xml/XPathNodeSet.h" | 30 #include "core/xml/XPathNodeSet.h" |
| 31 #include "wtf/text/WTFString.h" | 31 #include "wtf/text/WTFString.h" |
| 32 | 32 |
| 33 namespace WebCore { | 33 namespace WebCore { |
| 34 | 34 |
| 35 namespace XPath { | 35 namespace XPath { |
| 36 | 36 |
| 37 class ValueData : public RefCountedWillBeGarbageCollectedFinalized<Value
Data> { | 37 class ValueData : public RefCountedWillBeGarbageCollectedFinalized<ValueData> { |
| 38 public: | 38 public: |
| 39 static PassRefPtrWillBeRawPtr<ValueData> create() { return adoptRefW
illBeNoop(new ValueData); } | 39 static PassRefPtrWillBeRawPtr<ValueData> create() { return adoptRefWillBeNoo
p(new ValueData); } |
| 40 static PassRefPtrWillBeRawPtr<ValueData> create(const NodeSet& nodeS
et) { return adoptRefWillBeNoop(new ValueData(nodeSet)); } | 40 static PassRefPtrWillBeRawPtr<ValueData> create(const NodeSet& nodeSet) { re
turn adoptRefWillBeNoop(new ValueData(nodeSet)); } |
| 41 static PassRefPtrWillBeRawPtr<ValueData> create(PassOwnPtrWillBeRawP
tr<NodeSet> nodeSet) { return adoptRefWillBeNoop(new ValueData(nodeSet)); } | 41 static PassRefPtrWillBeRawPtr<ValueData> create(PassOwnPtrWillBeRawPtr<NodeS
et> nodeSet) { return adoptRefWillBeNoop(new ValueData(nodeSet)); } |
| 42 static PassRefPtrWillBeRawPtr<ValueData> create(const String& string
) { return adoptRefWillBeNoop(new ValueData(string)); } | 42 static PassRefPtrWillBeRawPtr<ValueData> create(const String& string) { retu
rn adoptRefWillBeNoop(new ValueData(string)); } |
| 43 void trace(Visitor*); | 43 void trace(Visitor*); |
| 44 NodeSet& nodeSet() { return *m_nodeSet; } | 44 NodeSet& nodeSet() { return *m_nodeSet; } |
| 45 | 45 |
| 46 String m_string; | 46 String m_string; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 ValueData() : m_nodeSet(NodeSet::create()) { } | 49 ValueData() : m_nodeSet(NodeSet::create()) { } |
| 50 explicit ValueData(const NodeSet& nodeSet) : m_nodeSet(NodeSet::crea
te(nodeSet)) { } | 50 explicit ValueData(const NodeSet& nodeSet) : m_nodeSet(NodeSet::create(nodeS
et)) { } |
| 51 explicit ValueData(PassOwnPtrWillBeRawPtr<NodeSet> nodeSet) : m_node
Set(nodeSet) { } | 51 explicit ValueData(PassOwnPtrWillBeRawPtr<NodeSet> nodeSet) : m_nodeSet(node
Set) { } |
| 52 explicit ValueData(const String& string) : m_string(string), m_nodeS
et(NodeSet::create()) { } | 52 explicit ValueData(const String& string) : m_string(string), m_nodeSet(NodeS
et::create()) { } |
| 53 | 53 |
| 54 OwnPtrWillBeMember<NodeSet> m_nodeSet; | 54 OwnPtrWillBeMember<NodeSet> m_nodeSet; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Copying Value objects makes their data partially shared, so care has
to be taken when dealing with copies. | 57 // Copying Value objects makes their data partially shared, so care has to be ta
ken when dealing with copies. |
| 58 class Value { | 58 class Value { |
| 59 DISALLOW_ALLOCATION(); | 59 DISALLOW_ALLOCATION(); |
| 60 public: | 60 public: |
| 61 enum Type { NodeSetValue, BooleanValue, NumberValue, StringValue }; | 61 enum Type { NodeSetValue, BooleanValue, NumberValue, StringValue }; |
| 62 | 62 |
| 63 Value(unsigned value) : m_type(NumberValue), m_bool(false), m_number
(value) {} | 63 Value(unsigned value) : m_type(NumberValue), m_bool(false), m_number(value)
{ } |
| 64 Value(unsigned long value) : m_type(NumberValue), m_bool(false), m_n
umber(value) {} | 64 Value(unsigned long value) : m_type(NumberValue), m_bool(false), m_number(va
lue) { } |
| 65 Value(double value) : m_type(NumberValue), m_bool(false), m_number(v
alue) {} | 65 Value(double value) : m_type(NumberValue), m_bool(false), m_number(value) {
} |
| 66 | 66 |
| 67 Value(const char* value) : m_type(StringValue), m_bool(false), m_num
ber(0), m_data(ValueData::create(value)) {} | 67 Value(const char* value) : m_type(StringValue), m_bool(false), m_number(0),
m_data(ValueData::create(value)) { } |
| 68 Value(const String& value) : m_type(StringValue), m_bool(false), m_n
umber(0), m_data(ValueData::create(value)) {} | 68 Value(const String& value) : m_type(StringValue), m_bool(false), m_number(0)
, m_data(ValueData::create(value)) { } |
| 69 Value(const NodeSet& value) : m_type(NodeSetValue), m_bool(false), m
_number(0), m_data(ValueData::create(value)) {} | 69 Value(const NodeSet& value) : m_type(NodeSetValue), m_bool(false), m_number(
0), m_data(ValueData::create(value)) { } |
| 70 Value(Node* value) : m_type(NodeSetValue), m_bool(false), m_number(0
), m_data(ValueData::create()) { m_data->nodeSet().append(value); } | 70 Value(Node* value) : m_type(NodeSetValue), m_bool(false), m_number(0), m_dat
a(ValueData::create()) { m_data->nodeSet().append(value); } |
| 71 void trace(Visitor*); | 71 void trace(Visitor*); |
| 72 | 72 |
| 73 // This is needed to safely implement constructing from bool - with
normal function overloading, any pointer type would match. | 73 // This is needed to safely implement constructing from bool - with normal |
| 74 template<typename T> Value(T); | 74 // function overloading, any pointer type would match. |
| 75 template<typename T> Value(T); |
| 75 | 76 |
| 76 static const struct AdoptTag {} adopt; | 77 static const struct AdoptTag { } adopt; |
| 77 Value(PassOwnPtrWillBeRawPtr<NodeSet> value, const AdoptTag&) : m_ty
pe(NodeSetValue), m_bool(false), m_number(0), m_data(ValueData::create(value))
{ } | 78 Value(PassOwnPtrWillBeRawPtr<NodeSet> value, const AdoptTag&) : m_type(NodeS
etValue), m_bool(false), m_number(0), m_data(ValueData::create(value)) { } |
| 78 | 79 |
| 79 Type type() const { return m_type; } | 80 Type type() const { return m_type; } |
| 80 | 81 |
| 81 bool isNodeSet() const { return m_type == NodeSetValue; } | 82 bool isNodeSet() const { return m_type == NodeSetValue; } |
| 82 bool isBoolean() const { return m_type == BooleanValue; } | 83 bool isBoolean() const { return m_type == BooleanValue; } |
| 83 bool isNumber() const { return m_type == NumberValue; } | 84 bool isNumber() const { return m_type == NumberValue; } |
| 84 bool isString() const { return m_type == StringValue; } | 85 bool isString() const { return m_type == StringValue; } |
| 85 | 86 |
| 86 const NodeSet& toNodeSet() const; | 87 const NodeSet& toNodeSet() const; |
| 87 NodeSet& modifiableNodeSet(); | 88 NodeSet& modifiableNodeSet(); |
| 88 bool toBoolean() const; | 89 bool toBoolean() const; |
| 89 double toNumber() const; | 90 double toNumber() const; |
| 90 String toString() const; | 91 String toString() const; |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 Type m_type; | 94 Type m_type; |
| 94 bool m_bool; | 95 bool m_bool; |
| 95 double m_number; | 96 double m_number; |
| 96 RefPtrWillBeMember<ValueData> m_data; | 97 RefPtrWillBeMember<ValueData> m_data; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 template<> | 100 template<> |
| 100 inline Value::Value(bool value) | 101 inline Value::Value(bool value) |
| 101 : m_type(BooleanValue) | 102 : m_type(BooleanValue) |
| 102 , m_bool(value) | 103 , m_bool(value) |
| 103 , m_number(0) | 104 , m_number(0) |
| 104 { | 105 { |
| 105 } | |
| 106 } | |
| 107 } | 106 } |
| 108 | 107 |
| 109 #endif // XPath_Value_H | 108 } |
| 109 |
| 110 } |
| 111 #endif // XPathValue_h |
| OLD | NEW |