Apache Log4cxx  Version 1.3.1
Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_HELPERS_OBJECT_H
19#define _LOG4CXX_HELPERS_OBJECT_H
20
21#include <log4cxx/logstring.h>
25
26
27#define DECLARE_LOG4CXX_CLAZZ_OBJECT(object)\
28 public:\
29 class Clazz##object : public helpers::Class\
30 {\
31 public:\
32 Clazz##object() : helpers::Class() {}\
33 virtual ~Clazz##object() {}\
34 virtual LOG4CXX_NS::LogString getName() const { return LOG4CXX_STR(#object); } \
35 };\
36 static const helpers::Class& getStaticClass(); \
37 static const LOG4CXX_NS::helpers::ClassRegistration& registerClass();
38
39#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)\
40 DECLARE_LOG4CXX_CLAZZ_OBJECT(object)\
41 const helpers::Class& getClass() const override;
42
43#define DECLARE_LOG4CXX_OBJECT(object)\
44 public:\
45 class Clazz##object : public helpers::Class\
46 {\
47 public:\
48 Clazz##object() : helpers::Class() {}\
49 virtual ~Clazz##object() {}\
50 virtual LOG4CXX_NS::LogString getName() const { return LOG4CXX_STR(#object); } \
51 virtual object* newInstance() const\
52 {\
53 return new object();\
54 }\
55 };\
56 const helpers::Class& getClass() const override;\
57 static const helpers::Class& getStaticClass(); \
58 static const LOG4CXX_NS::helpers::ClassRegistration& registerClass();
59
60#define DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)\
61 public:\
62 const helpers::Class& getClass() const override;\
63 static const helpers::Class& getStaticClass();\
64 static const LOG4CXX_NS::helpers::ClassRegistration& registerClass();
65
66#define IMPLEMENT_LOG4CXX_OBJECT(object)\
67 const ::LOG4CXX_NS::helpers::Class& object::getClass() const { return getStaticClass(); }\
68 const ::LOG4CXX_NS::helpers::Class& object::getStaticClass() { \
69 static ::LOG4CXX_NS::helpers::WideLife<Clazz##object> theClass; \
70 return theClass; \
71 } \
72 const LOG4CXX_NS::helpers::ClassRegistration& object::registerClass() { \
73 static ::LOG4CXX_NS::helpers::WideLife<::LOG4CXX_NS::helpers::ClassRegistration> classReg(object::getStaticClass); \
74 return classReg; \
75 }\
76 namespace LOG4CXX_NS { namespace classes { \
77 const ::LOG4CXX_NS::helpers::ClassRegistration& object##Registration = object::registerClass(); \
78 } }
79
80
81#define IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)\
82 const LOG4CXX_NS::helpers::Class& object::getClass() const { return getStaticClass(); }\
83 const LOG4CXX_NS::helpers::Class& object::getStaticClass() { \
84 static LOG4CXX_NS::helpers::WideLife<class> theClass; \
85 return theClass; \
86 } \
87 const LOG4CXX_NS::helpers::ClassRegistration& object::registerClass() { \
88 static LOG4CXX_NS::helpers::WideLife<LOG4CXX_NS::helpers::ClassRegistration> classReg(object::getStaticClass); \
89 return classReg; \
90 }\
91 namespace LOG4CXX_NS { namespace classes { \
92 const LOG4CXX_NS::helpers::ClassRegistration& object##Registration = object::registerClass(); \
93 } }
94
95namespace LOG4CXX_NS
96{
97class AppenderSkeleton;
98class Logger;
99
100namespace helpers
101{
102class Pool;
103
105class LOG4CXX_EXPORT Object
106{
107 public:
108 virtual ~Object() {}
109 virtual const helpers::Class& getClass() const = 0;
110 virtual bool instanceof(const Class& clazz) const = 0;
111 virtual const void* cast(const Class& clazz) const = 0;
113};
115}
116
123template<typename Ret,
124 typename Type,
125 bool = std::is_base_of<Ret, helpers::Object>::value,
126 bool = std::is_base_of<Type, helpers::Object>::value>
127std::shared_ptr<Ret> cast(const std::shared_ptr<Type>& incoming)
128{
129 if(!incoming)
130 {
131 return std::shared_ptr<Ret>();
132 }
133
134 Ret* casted = reinterpret_cast<Ret*>(const_cast<void*>(incoming->cast(Ret::getStaticClass())));
135
136 if ( casted )
137 {
138 return std::shared_ptr<Ret>( incoming, casted );
139 }
140
141 return std::shared_ptr<Ret>();
142}
143
144}
145
146#define BEGIN_LOG4CXX_CAST_MAP()\
147 const void * cast(const helpers::Class& clazz) const override\
148 {\
149 const void * object = 0;\
150 if (&clazz == &helpers::Object::getStaticClass()) return (const helpers::Object *)this;
151
152#define END_LOG4CXX_CAST_MAP()\
153 return object;\
154 }\
155 bool instanceof(const helpers::Class& clazz) const override\
156 { return cast(clazz) != 0; }
157
158#define LOG4CXX_CAST_ENTRY(Interface)\
159 if (&clazz == &Interface::getStaticClass()) return (const Interface *)this;
160
161#define LOG4CXX_CAST_ENTRY2(Interface, interface2)\
162 if (&clazz == &Interface::getStaticClass()) return (Interface *)(interface2 *)this;
163
164#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)\
165 object = Interface::cast(clazz);\
166 if (object != 0) return object;
167
168#endif //_LOG4CXX_HELPERS_OBJECT_H
Definition: class.h:32
base class for java-like objects.
Definition: object.h:106
virtual const helpers::Class & getClass() const =0
virtual ~Object()
Definition: object.h:108
virtual const void * cast(const Class &clazz) const =0
virtual bool instanceof(const Class &clazz) const =0
std::shared_ptr< Ret > cast(const std::shared_ptr< Type > &incoming)
Attempt to cast one Object to another kind of Object.
Definition: object.h:127
LOG4CXX_PTR_DEF(Appender)
#define DECLARE_LOG4CXX_CLAZZ_OBJECT(object)
Definition: object.h:27