VMware GemFire Native C++ Reference  9.1
SharedPtrHelper.hpp
1 #pragma once
2 
3 #ifndef GEODE_SHAREDPTRHELPER_H_
4 #define GEODE_SHAREDPTRHELPER_H_
5 
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements. See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "geode_globals.hpp"
24 #include "TypeHelper.hpp"
25 #include <typeinfo>
26 
27 namespace apache {
28 namespace geode {
29 namespace client {
30 
31 class SharedBase;
32 
36  public:
37  static void throwNullPointerException(const char* ename);
38 
39  static void throwClassCastException(const char* msg, const char* fromType,
40  const char* toType);
41 };
42 
43 /* Helper function template for type conversion.
44  */
45 template <class Target, class Src>
46 Target* getTargetHelper(Src* ptr,
47  apache::geode::client::TypeHelper::yes_type yes) {
48  return ptr;
49 }
50 
51 /* Helper function template for type conversion.
52  */
53 template <class Target, class Src>
54 Target* getTargetHelper(Src* ptr,
55  apache::geode::client::TypeHelper::no_type no) {
56  Target* tptr = dynamic_cast<Target*>(ptr);
57  if (tptr) {
58  return tptr;
59  } else {
60  SPEHelper::throwClassCastException("getTargetHelper: cast failed",
61  typeid(ptr).name(), typeid(tptr).name());
62  return NULL;
63  }
64 }
65 
66 /* Helper function template for type conversion.
67  */
68 template <class Target, class Src>
69 Target* getTarget(Src* ptr) {
70  return getTargetHelper<Target>(ptr, GF_SRC_IS_TARGET_TYPE(Target, Src));
71 }
72 
73 /* Helper function template for type conversion.
74  */
75 template <class Src>
76 SharedBase* getSB(Src* ptr) {
77  return getTarget<SharedBase>(ptr);
78 }
79 } // namespace client
80 } // namespace geode
81 } // namespace apache
82 
83 #endif // GEODE_SHAREDPTRHELPER_H_
Helper class for SharedPtr exceptions.
Definition: SharedPtrHelper.hpp:35
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
#define CPPCACHE_EXPORT
Defines a Geode CPPCACHE export.
Definition: geode_base.hpp:58
This abstract base class is the base class of all user objects that have the shared capability of ref...
Definition: SharedBase.hpp:40
This namespace contains all the Geode C++ API classes, enumerations and globals.

Pivotal GemFire C++ Cache API Documentation