make #includes consistent
[hiphop-php.git] / hphp / runtime / base / list_assignment.cpp
blobf274a0613dc2a310daa06c748d98db9289f81e40
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- 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 #include "hphp/runtime/base/list_assignment.h"
18 #include "hphp/runtime/base/complex_types.h"
20 namespace HPHP {
21 ///////////////////////////////////////////////////////////////////////////////
22 // ListAssignmentElement
24 ListAssignmentElement::ListAssignmentElement(Variant &var, int index, ...)
25 : m_var(var) {
26 va_list ap;
27 va_start(ap, index);
28 while (index != -1) {
29 m_indices.push_back(index);
30 index = va_arg(ap, int);
32 va_end(ap);
35 void ListAssignmentElement::assign(CArrRef data) {
36 assert(!m_indices.empty());
37 Variant tmp = data;
38 unsigned int size = m_indices.size();
39 for (unsigned int i = 0; i < size; i++) {
40 tmp = tmp.rvalAt(m_indices[i]);
42 m_var = tmp;
45 ///////////////////////////////////////////////////////////////////////////////
46 // global function
48 Variant list_assign(CVarRef data, ListAssignmentElement *elem, ...) {
49 Array adata = data.toArray();
50 vector<ListAssignmentElement *> elems;
52 va_list ap;
53 va_start(ap, elem);
54 while (elem) {
55 elems.push_back(elem);
56 elem = va_arg(ap, ListAssignmentElement *);
58 va_end(ap);
60 for (int i = elems.size() - 1; i >= 0; i--) {
61 elems[i]->assign(adata);
62 delete elems[i];
64 return data;
67 ///////////////////////////////////////////////////////////////////////////////