Skip to content

Commit fe870cb

Browse files
committed
Fixed indentation.
1 parent e214cf6 commit fe870cb

File tree

3 files changed

+101
-102
lines changed

3 files changed

+101
-102
lines changed

include/network/logging/logging.hpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,60 @@
66

77
namespace network { namespace logging {
88

9-
class log_record;
10-
11-
//using log_record_handler = std::function< void (const std::string&) >; // use this when VS can compile it...
12-
typedef std::function< void (const log_record&) > log_record_handler;
9+
class log_record;
1310

14-
void set_log_record_handler( log_record_handler handler );
15-
void log( const log_record& message );
16-
17-
namespace handler
18-
{
19-
log_record_handler get_std_log_handler();
20-
log_record_handler get_default_log_handler();
21-
}
22-
23-
/** Helper to build a log record as a stream. */
24-
class log_record
25-
{
26-
public:
27-
log_record(){} // = default;
11+
//using log_record_handler = std::function< void (const std::string&) >; // use this when VS can compile it...
12+
typedef std::function< void (const log_record&) > log_record_handler;
2813

29-
// Implicit construction from string
30-
log_record( const std::string& message )
31-
{
32-
write( message );
33-
}
14+
void set_log_record_handler( log_record_handler handler );
15+
void log( const log_record& message );
3416

35-
~log_record()
36-
{
37-
log( *this );
38-
}
39-
40-
template< typename TypeOfSomething >
41-
log_record& write( const TypeOfSomething& something ) // THINK: use universal references?
42-
{
43-
m_text_stream << something;
44-
return *this;
45-
}
17+
namespace handler
18+
{
19+
log_record_handler get_std_log_handler();
20+
log_record_handler get_default_log_handler();
21+
}
4622

47-
std::string full_message() const { return m_text_stream.str(); }
23+
/** Helper to build a log record as a stream. */
24+
class log_record
25+
{
26+
public:
27+
log_record(){} // = default;
4828

49-
private:
50-
// disable copy
51-
log_record( const log_record& ); // = delete;
52-
log_record& operator=( const log_record& ); // = delete;
29+
// Implicit construction from string
30+
log_record( const std::string& message )
31+
{
32+
write( message );
33+
}
5334

54-
std::ostringstream m_text_stream; // stream in which we build the message
55-
56-
};
57-
58-
template< typename TypeOfSomething >
59-
inline log_record& operator<<( log_record& log, const TypeOfSomething& something ) // THINK: use universal references?
60-
{
61-
return log.write( something );
62-
}
35+
~log_record()
36+
{
37+
log( *this );
38+
}
39+
40+
template< typename TypeOfSomething >
41+
log_record& write( const TypeOfSomething& something ) // THINK: use universal references?
42+
{
43+
m_text_stream << something;
44+
return *this;
45+
}
46+
47+
std::string full_message() const { return m_text_stream.str(); }
48+
49+
private:
50+
// disable copy
51+
log_record( const log_record& ); // = delete;
52+
log_record& operator=( const log_record& ); // = delete;
53+
54+
std::ostringstream m_text_stream; // stream in which we build the message
55+
56+
};
57+
58+
template< typename TypeOfSomething >
59+
inline log_record& operator<<( log_record& log, const TypeOfSomething& something ) // THINK: use universal references?
60+
{
61+
return log.write( something );
62+
}
6363

6464
}}
6565

libs/network/src/CMakeLists.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
2121
endif()
2222

2323
if( CPP-NETLIB_ALWAYS_LOGGING )
24-
add_definitions( /D NETWORK_ENABLE_LOGGING )
24+
add_definitions( /D NETWORK_ENABLE_LOGGING )
2525
endif()
2626

2727
if( NOT CPP-NETLIB_DISABLE_LOGGING )
28-
set( CPP-NETLIB_LOGGING_SRCS
29-
logging/logging.cpp
30-
)
31-
add_library(cppnetlib-logging ${CPP-NETLIB_LOGGING_SRCS})
32-
foreach (src_file ${CPP-NETLIB_LOGGING_SRCS})
33-
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
34-
set_source_files_properties(${src_file}
35-
PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
36-
endif()
37-
endforeach(src_file)
38-
39-
# this library name is defined only if we created the target
40-
# if not then it will be empty
41-
set( CPP-NETLIB_LOGGING_LIB cppnetlib-logging )
42-
28+
set( CPP-NETLIB_LOGGING_SRCS
29+
logging/logging.cpp
30+
)
31+
add_library(cppnetlib-logging ${CPP-NETLIB_LOGGING_SRCS})
32+
foreach (src_file ${CPP-NETLIB_LOGGING_SRCS})
33+
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
34+
set_source_files_properties(${src_file}
35+
PROPERTIES COMPILE_FLAGS ${CPP-NETLIB_CXXFLAGS})
36+
endif()
37+
endforeach(src_file)
38+
39+
# this library name is defined only if we created the target
40+
# if not then it will be empty
41+
set( CPP-NETLIB_LOGGING_LIB cppnetlib-logging )
42+
4343
endif()
4444

4545
set(CPP-NETLIB_URI_SRCS uri/uri.cpp uri/schemes.cpp uri/normalize.cpp)

libs/network/src/logging/logging.cpp

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#ifdef NETWORK_NO_LIB
32
#undef NETWORK_NO_LIB
43
#endif
@@ -10,43 +9,43 @@
109

1110
namespace network { namespace logging {
1211

13-
namespace handler
14-
{
15-
namespace
16-
{
17-
void std_log_handler( const log_record& log )
18-
{
19-
std::cerr << log.full_message() << std::endl;
20-
}
21-
}
22-
23-
log_record_handler get_std_log_handler() { return &std_log_handler; }
24-
log_record_handler get_default_log_handler() { return &std_log_handler; }
25-
}
26-
27-
28-
namespace
29-
{
30-
// the log handler have to manage itself the thread safety on call
31-
log_record_handler current_log_record_handler = handler::std_log_handler;
32-
boost::upgrade_mutex mutex_log_handler; // we still need to not change the log handler concurrently
33-
}
34-
35-
36-
void set_log_record_handler( log_record_handler handler )
37-
{
38-
boost::lock_guard<boost::upgrade_mutex> write_lock( mutex_log_handler );
39-
current_log_record_handler = handler;
40-
}
41-
42-
void log( const log_record& log )
43-
{
44-
boost::shared_lock<boost::upgrade_mutex> read_lock( mutex_log_handler );
45-
if( current_log_record_handler )
46-
{
47-
current_log_record_handler( log );
48-
}
49-
}
12+
namespace handler
13+
{
14+
namespace
15+
{
16+
void std_log_handler( const log_record& log )
17+
{
18+
std::cerr << log.full_message() << std::endl;
19+
}
20+
}
21+
22+
log_record_handler get_std_log_handler() { return &std_log_handler; }
23+
log_record_handler get_default_log_handler() { return &std_log_handler; }
24+
}
25+
26+
27+
namespace
28+
{
29+
// the log handler have to manage itself the thread safety on call
30+
log_record_handler current_log_record_handler = handler::std_log_handler;
31+
boost::upgrade_mutex mutex_log_handler; // we still need to not change the log handler concurrently
32+
}
33+
34+
35+
void set_log_record_handler( log_record_handler handler )
36+
{
37+
boost::lock_guard<boost::upgrade_mutex> write_lock( mutex_log_handler );
38+
current_log_record_handler = handler;
39+
}
40+
41+
void log( const log_record& log )
42+
{
43+
boost::shared_lock<boost::upgrade_mutex> read_lock( mutex_log_handler );
44+
if( current_log_record_handler )
45+
{
46+
current_log_record_handler( log );
47+
}
48+
}
5049

5150

5251
}}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy