parse effect encapsulation syntax
[hiphop-php.git] / hphp / hhbbc / array-like-map.h
blob4907f82fa72d885ffbe6b36724d3c346f5ebbc5b
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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 +----------------------------------------------------------------------+
16 #pragma once
18 #include "hphp/util/insertion-ordered-map.h"
20 #include "hphp/hhbbc/misc.h"
21 #include "hphp/runtime/base/typed-value.h"
23 namespace HPHP { namespace HHBBC {
25 struct Type;
27 struct ArrayLikeMapHash {
28 size_t operator()(const TypedValue& c) const { return c.m_data.num; }
29 size_t operator()(LSString s) const { return (size_t)s.get(); }
30 size_t operator()(int64_t i) const { return i; }
33 struct ArrayLikeMapEqual {
34 bool operator()(const TypedValue& c1, const TypedValue& c2) const {
35 return c1.m_type == c2.m_type && c1.m_data.num == c2.m_data.num;
37 bool operator()(SString s, const TypedValue& c) const {
38 return isStringType(c.m_type) && c.m_data.pstr == s;
40 bool operator()(int64_t i, const TypedValue& c) const {
41 return c.m_type == KindOfInt64 && c.m_data.num == i;
43 bool operator()(LSString s1, LSString s2) const {
44 return s1 == s2;
46 bool operator()(int64_t i1, int64_t i2) const {
47 return i1 == i2;
52 * This is an insertion-order preserving hash map. Its used to emulate
53 * the behavior of php and hack arrays in hhbbc. Handling of int-like
54 * string keys must be done by the user.
56 template <class K, class V = Type>
57 using ArrayLikeMap =
58 InsertionOrderedMap<K,V,ArrayLikeMapHash, ArrayLikeMapEqual>;
60 } }