2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_TV_CONVERSIONS_H_
18 #define incl_HPHP_TV_CONVERSIONS_H_
20 #include "hphp/runtime/base/datatype.h"
21 #include "hphp/runtime/base/req-root.h"
22 #include "hphp/runtime/base/type-array.h"
23 #include "hphp/runtime/base/type-object.h"
24 #include "hphp/runtime/base/type-string.h"
25 #include "hphp/runtime/base/typed-value.h"
31 ///////////////////////////////////////////////////////////////////////////////
33 * TypedValue conversions that update `tv' in place (decrefing the old value,
36 * We have two kinds of type conversions:
38 * - Cast forcibly changes the value to the new type and will not fail (though
39 * the result may be silly).
40 * - Coerce attempts to convert the type and returns false on failure.
44 void tvCastTo##kind##InPlace(TypedValue* tv); \
45 bool tvCoerceParamTo##kind##InPlace(TypedValue* tv, \
60 void tvCastToVArrayInPlace(TypedValue
* tv
);
61 void tvCastToDArrayInPlace(TypedValue
* tv
);
63 ALWAYS_INLINE
void tvCastInPlace(TypedValue
* tv
, DataType DType
) {
65 if (DType == KindOf##kind) { tvCastTo##kind##InPlace(tv); return; }
80 ALWAYS_INLINE
bool tvCoerceParamInPlace(TypedValue
* tv
, DataType DType
,
83 if (DType == KindOf##kind) \
84 return tvCoerceParamTo##kind##InPlace(tv, \
101 * Non-in-place casts.
103 bool tvCastToBoolean(TypedValue tv
);
104 int64_t tvCastToInt64(TypedValue tv
);
105 double tvCastToDouble(TypedValue tv
);
106 String
tvCastToString(TypedValue tv
);
107 Array
tvCastToArrayLike(TypedValue tv
);
108 Object
tvCastToObject(TypedValue tv
);
110 StringData
* tvCastToStringData(TypedValue tv
);
111 ArrayData
* tvCastToArrayLikeData(TypedValue tv
);
112 ObjectData
* tvCastToObjectData(TypedValue tv
);
115 * Convert a cell to various raw data types, without changing the Cell.
117 bool cellToBool(Cell
);
118 int64_t cellToInt(Cell
);
119 double cellToDouble(Cell
);
122 * Convert `tv' or `cell' to a valid array key for `ad', or throw an exception.
124 Cell
cellToKey(Cell cell
, const ArrayData
* ad
);
125 Cell
tvToKey(TypedValue tv
, const ArrayData
* ad
);
128 * Convert a string to a TypedNum following PHP semantics, allowing strings
129 * that have only a partial number in them (i.e. the string may have junk after
132 TypedNum
stringToNumeric(const StringData
*);
134 ///////////////////////////////////////////////////////////////////////////////
138 #include "hphp/runtime/base/tv-conversions-inl.h"