Bug 886842 - Add clang trunk builds for ASan. r=froydnj
[gecko.git] / content / smil / SMILStringType.cpp
blob6b549939d4effea8b22190b8e85b7c82ab8d5ef3
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "SMILStringType.h"
7 #include "nsSMILValue.h"
8 #include "nsDebug.h"
9 #include "nsString.h"
11 namespace mozilla {
13 void
14 SMILStringType::Init(nsSMILValue& aValue) const
16 NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
17 aValue.mU.mPtr = new nsString();
18 aValue.mType = this;
21 void
22 SMILStringType::Destroy(nsSMILValue& aValue) const
24 NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
25 delete static_cast<nsAString*>(aValue.mU.mPtr);
26 aValue.mU.mPtr = nullptr;
27 aValue.mType = nsSMILNullType::Singleton();
30 nsresult
31 SMILStringType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const
33 NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types");
34 NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value");
36 const nsAString* src = static_cast<const nsAString*>(aSrc.mU.mPtr);
37 nsAString* dst = static_cast<nsAString*>(aDest.mU.mPtr);
38 *dst = *src;
39 return NS_OK;
42 bool
43 SMILStringType::IsEqual(const nsSMILValue& aLeft,
44 const nsSMILValue& aRight) const
46 NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types");
47 NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value");
49 const nsAString* leftString =
50 static_cast<const nsAString*>(aLeft.mU.mPtr);
51 const nsAString* rightString =
52 static_cast<nsAString*>(aRight.mU.mPtr);
53 return *leftString == *rightString;
56 nsresult
57 SMILStringType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
58 uint32_t aCount) const
60 NS_PRECONDITION(aValueToAdd.mType == aDest.mType,
61 "Trying to add invalid types");
62 NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type");
63 return NS_ERROR_FAILURE; // string values can't be added to each other
66 nsresult
67 SMILStringType::ComputeDistance(const nsSMILValue& aFrom,
68 const nsSMILValue& aTo,
69 double& aDistance) const
71 NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types");
72 NS_PRECONDITION(aFrom.mType == this, "Unexpected source type");
73 return NS_ERROR_FAILURE; // there is no concept of distance between string values
76 nsresult
77 SMILStringType::Interpolate(const nsSMILValue& aStartVal,
78 const nsSMILValue& aEndVal,
79 double aUnitDistance,
80 nsSMILValue& aResult) const
82 NS_PRECONDITION(aStartVal.mType == aEndVal.mType,
83 "Trying to interpolate different types");
84 NS_PRECONDITION(aStartVal.mType == this,
85 "Unexpected types for interpolation");
86 NS_PRECONDITION(aResult.mType == this, "Unexpected result type");
87 return NS_ERROR_FAILURE; // string values do not interpolate
90 } // namespace mozilla