Move io_tests to folly/io/async/test
[hiphop-php.git] / hphp / runtime / base / req-ptr.cpp
blobc88d8ddb395617a0210573f2625142facd1f96c3
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 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/req-ptr.h"
18 #include "hphp/runtime/base/object-data.h"
19 #include "hphp/runtime/base/resource-data.h"
20 #include "hphp/runtime/base/exceptions.h"
21 #include "hphp/runtime/base/type-object.h"
22 #include "hphp/runtime/base/type-resource.h"
23 #include "hphp/runtime/base/type-variant.h"
25 namespace HPHP {
27 void throw_invalid_object_type(ResourceData* p) {
28 if (!p) throw_null_pointer_exception();
29 throw_invalid_object_type(p->o_getClassName().c_str());
32 void throw_invalid_object_type(ObjectData* p) {
33 if (!p) throw_null_pointer_exception();
34 throw_invalid_object_type(p->getClassName().c_str());
37 void throw_invalid_object_type(const OptResource& p) {
38 throw_invalid_object_type(deref<ResourceData>(p));
41 void throw_invalid_object_type(const Object& p) {
42 throw_invalid_object_type(p.get());
45 void throw_invalid_object_type(const Variant& p) {
46 auto tv = p.asTypedValue();
47 switch (tv->m_type) {
48 case KindOfNull:
49 case KindOfUninit:
50 throw_null_pointer_exception();
51 case KindOfObject:
52 throw_invalid_object_type(tv->m_data.pobj->getClassName().c_str());
53 case KindOfResource:
54 throw_invalid_object_type(
55 tv->m_data.pres->data()->o_getClassName().c_str()
57 default:
58 throw_invalid_object_type(tname(tv->m_type).c_str());