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_SPI_LOCATION_LOCATIONINFO_H
19 #define _LOG4CXX_SPI_LOCATION_LOCATIONINFO_H
20 
21 #include <log4cxx/log4cxx.h>
22 #include <string>
23 #include <log4cxx/helpers/objectoutputstream.h>
24 
25 namespace log4cxx
26 {
27 namespace spi
28 {
29 /**
30  * This class represents the location of a logging statement.
31  *
32  */
33 class LOG4CXX_EXPORT LocationInfo
34 {
35 	public:
36 
37 
38 
39 		/**
40 		  *   When location information is not available the constant
41 		  * <code>NA</code> is returned. Current value of this string constant is <b>?</b>.
42 		  */
43 		static const char* const NA;
44 		static const char* const NA_METHOD;
45 
46 		static const LocationInfo& getLocationUnavailable();
47 
48 
49 
50 		/**
51 		 *   Constructor.
52 		 *   @remarks Used by LOG4CXX_LOCATION to generate
53 		 *       location info for current code site
54 		 */
55 		LocationInfo( const char* const fileName,
56 			const char* const functionName,
57 			int lineNumber);
58 
59 		/**
60 		 *   Default constructor.
61 		 */
62 		LocationInfo();
63 
64 		/**
65 		 *   Copy constructor.
66 		 *   @param src source location
67 		 */
68 		LocationInfo( const LocationInfo& src );
69 
70 		/**
71 		 *  Assignment operator.
72 		 * @param src source location
73 		 */
74 		LocationInfo& operator = ( const LocationInfo& src );
75 
76 		/**
77 		 *   Resets location info to default state.
78 		 */
79 		void clear();
80 
81 
82 		/** Return the class name of the call site. */
83 		const std::string getClassName() const;
84 
85 		/**
86 		 *   Return the file name of the caller.
87 		 *   @returns file name, may be null.
88 		 */
89 		const char* getFileName() const;
90 
91 		/**
92 		  *   Returns the line number of the caller.
93 		  * @returns line number, -1 if not available.
94 		  */
95 		int getLineNumber() const;
96 
97 		/** Returns the method name of the caller. */
98 		const std::string getMethodName() const;
99 
100 		void write(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p) const;
101 
102 
103 	private:
104 		/** Caller's line number. */
105 		int lineNumber;
106 
107 		/** Caller's file name. */
108 		const char* fileName;
109 
110 		/** Caller's method name. */
111 		const char* methodName;
112 
113 
114 };
115 }
116 }
117 
118 #if !defined(LOG4CXX_LOCATION)
119 #if defined(_MSC_VER)
120 	#if _MSC_VER >= 1300
121 		#define __LOG4CXX_FUNC__ __FUNCSIG__
122 	#endif
123 #else
124 	#if defined(__GNUC__)
125 		#define __LOG4CXX_FUNC__ __PRETTY_FUNCTION__
126 	#else
127 		#if defined(__BORLANDC__)
128 			#define __LOG4CXX_FUNC__ __FUNC__
129 		#endif
130 	#endif
131 #endif
132 #if !defined(__LOG4CXX_FUNC__)
133 	#define __LOG4CXX_FUNC__ ""
134 #endif
135 #define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo(__FILE__,         \
136 	__LOG4CXX_FUNC__, \
137 	__LINE__)
138 #endif
139 
140 #endif //_LOG4CXX_SPI_LOCATION_LOCATIONINFO_H
141