Exemple #1
0
int
main()
try
{
// ![declare_context]
	fcppt::log::context context{
		fcppt::log::setting(
			fcppt::log::enabled_levels(
				fcppt::log::level::debug
			)
		)
	};
// ![declare_context]

// ![declare_root_logger]
	fcppt::log::name const root_name{
		FCPPT_TEXT("root")
	};

	fcppt::log::object root_logger{
		context,
		fcppt::log::parameters(
			root_name,
			fcppt::log::default_level_streams(
				fcppt::io::cout()
			),
			fcppt::log::format::optional_function{}
		)
	};
// ![declare_root_logger]

// ![declare_child_logger]
	fcppt::log::name const child_name{
		FCPPT_TEXT("child")
	};

	fcppt::log::object child_logger{
		root_logger,
		fcppt::log::parameters(
			child_name,
			fcppt::log::default_level_streams(
				fcppt::io::cout()
			),
			fcppt::log::format::optional_function{}
		)
	};
// ![declare_child_logger]

// ![log_debug]
	FCPPT_LOG_INFO(
		root_logger,
		fcppt::log::_
			<< FCPPT_TEXT("Print from root!")
	);

	FCPPT_LOG_INFO(
		child_logger,
		fcppt::log::_
			<< FCPPT_TEXT("Print from child!")
	);
// ![log_debug]

// ![context_set]
	context.set(
		fcppt::log::location_setting{
			fcppt::log::location{
				root_name
			}
			/
			child_name,
			fcppt::log::setting{
				fcppt::log::enabled_levels(
					fcppt::log::level::warning
				)
			}
		}
	);
// ![context_set]

// ![log_info]
	FCPPT_LOG_INFO(
		child_logger,
		fcppt::log::_
			<< FCPPT_TEXT("shouldn't be shown!")
	);
// ![log_info]

// ![context_set2]
	context.set(
		fcppt::log::location_setting{
			fcppt::log::location{
				root_name
			},
			fcppt::log::setting{
				fcppt::log::enabled_levels(
					fcppt::log::level::debug
				)
			}
		}
	);

	FCPPT_LOG_INFO(
		child_logger,
		fcppt::log::_
			<< FCPPT_TEXT("This is now shown!")
	);
// ![context_set2]

	return
		EXIT_SUCCESS;
}
catch(
	fcppt::exception const &_error
)
{
	fcppt::io::cerr()
		<< _error.string()
		<< FCPPT_TEXT('\n');

	return
		EXIT_FAILURE;
}
Exemple #2
0
bool
sge::wave::ignore_chunks_until(
	fcppt::log::object &_log,
	std::istream &_stream,
	sge::wave::header const &_header,
	fcppt::endianness::format const _endianness
)
{
	while(
		fcppt::optional::maybe(
			sge::wave::extract_header(
				_stream
			),
			fcppt::const_(
				false
			),
			[
				&_log,
				&_header
			](
				sge::wave::header const &_cur
			)
			{
				bool const do_continue{
					_header
					!=
					_cur
				};

				if(
					do_continue
				)
					FCPPT_LOG_INFO(
						_log,
						fcppt::log::_
							<<
							FCPPT_TEXT("detected unknown subchunk ")
							<<
							fcppt::from_std_string(
								std::string(
									_cur.begin(),
									_cur.end()
								)
							)
					);

				return
					do_continue;
			}
		)
	)
	{
		if(
			fcppt::optional::maybe(
				fcppt::io::read<
					std::uint32_t
				>(
					_stream,
					_endianness
				),
				fcppt::const_(
					true
				),
				[
					&_stream
				](
					std::uint32_t const _chunk_size
				)
				{
					_stream.seekg(
						fcppt::cast::size<
							std::streamoff
						>(
							fcppt::cast::to_signed(
								_chunk_size
							)
						),
						std::ios_base::cur
					);

					return
						false;
				}
			)
		)
			return
				false;
	}

	return
		_stream.good();
}
Exemple #3
0
sge::wave::optional_info
sge::wave::read_info(
	fcppt::log::object &_log,
	std::istream &_stream,
	sge::media::optional_name const &_name
)
{
	sge::wave::optional_header const riff(
		sge::wave::extract_header(
			_stream
		)
	);

	auto const compare_header_opt(
		[](
			sge::wave::optional_header const &_opt_header,
			sge::wave::header const &_expected
		)
		{
			return
				fcppt::optional::maybe(
					_opt_header,
					fcppt::const_(
						false
					),
					[
						&_expected
					](
						sge::wave::header const &_header
					)
					{
						return
							_header
							==
							_expected;
					}
				);
		}
	);

	bool const little_endian(
		compare_header_opt(
			riff,
			sge::wave::header{{
				'R', 'I', 'F', 'F'
			}}
		)
	);

	bool const big_endian(
		compare_header_opt(
			riff,
			sge::wave::header{{
				'R', 'I', 'F', 'X'
			}}
		)
	);

	if(
		!little_endian
		&&
		!big_endian
	)
		return
			sge::wave::optional_info();

	fcppt::endianness::format const endianness{
		little_endian
		?
			fcppt::endianness::format::little
		:
			fcppt::endianness::format::big
	};

	// throw away riff size
	fcppt::io::read<
		std::uint32_t
	>(
		_stream,
		endianness
	);

	if(
		!compare_header_opt(
			sge::wave::extract_header(
				_stream
			),
			sge::wave::header{{
				'W','A','V','E'
			}}
		)
	)
		return
			sge::wave::optional_info();

	if(
		!sge::wave::ignore_chunks_until(
			_log,
			_stream,
			sge::wave::header{{
				'f','m','t',' '
			}},
			endianness
		)
	)
		return
			sge::wave::optional_info();

	// ignore format chunk size
	fcppt::io::read<
		std::uint32_t
	>(
		_stream,
		endianness
	);

	if(
		fcppt::optional::maybe(
			fcppt::io::read<
				std::uint16_t
			>(
				_stream,
				endianness
			),
			fcppt::const_(
				true
			),
			[
				&_log,
				&_name
			](
				std::uint16_t const _format
			)
			{
				bool const unsupported{
					_format
					!=
					fcppt::literal<
						std::uint16_t
					>(
						1
					)
				};

				if(
					unsupported
				)
					FCPPT_LOG_INFO(
						_log,
						fcppt::log::_
							<<
							sge::media::error_string(
								_name,
								FCPPT_TEXT("wave file is not pcm encoded!")
							)
							<<
							FCPPT_TEXT(" Format is ")
							<<
							_format
					);

				return
					unsupported;
			}
		)
	)
		return
			sge::wave::optional_info();

	fcppt::optional::object<
		std::uint16_t
	> const channels(
		fcppt::io::read<
			std::uint16_t
		>(
			_stream,
			endianness
		)
	);

	fcppt::optional::object<
		std::uint32_t
	> const sample_rate(
		fcppt::io::read<
			std::uint32_t
		>(
			_stream,
			endianness
		)
	);

	// byte rate
	fcppt::io::read<
		std::uint32_t
	>(
		_stream,
		endianness
	);

	// block alignment
	fcppt::io::read<
		std::uint16_t
	>(
		_stream,
		endianness
	);

	fcppt::optional::object<
		std::uint16_t
	> const bits_per_sample(
		fcppt::io::read<
			std::uint16_t
		>(
			_stream,
			endianness
		)
	);

	if(
		!sge::wave::ignore_chunks_until(
			_log,
			_stream,
			sge::wave::header{{
				'd','a','t','a'
			}},
			endianness
		)
	)
		return
			sge::wave::optional_info();

	fcppt::optional::object<
		std::uint32_t
	> const data_size(
		fcppt::io::read<
			std::uint32_t
		>(
			_stream,
			endianness
		)
	);

	return
		fcppt::optional::maybe_multi(
			[]{
				return
					sge::wave::optional_info();
			},
			[
				endianness
			](
				std::uint16_t const _channels,
				std::uint32_t const _sample_rate,
				std::uint16_t const _bits_per_sample,
				std::uint32_t const _data_size
			)
			{
				sge::audio::channel_count const channels_result{
					fcppt::cast::size<
						sge::audio::channel_type
					>(
						_channels
					)
				};

				sge::audio::bits_per_sample const bits_per_sample_result{
					fcppt::cast::size<
						sge::audio::sample_count
					>(
						_bits_per_sample
					)
				};

				return
					sge::wave::optional_info{
						sge::wave::info{
							endianness,
							channels_result,
							sge::audio::sample_rate{
								fcppt::cast::size<
									sge::audio::sample_count
								>(
									_sample_rate
								)
							},
							bits_per_sample_result,
							fcppt::cast::size<
								sge::audio::sample_count
							>(
								_data_size
							)
							/
							channels_result.get()
							/
							sge::audio::bytes_per_sample(
								bits_per_sample_result
							)
						}
					};
			},
			channels,
			sample_rate,
			bits_per_sample,
			data_size
		);
}
Exemple #4
0
sanguis::client::config::settings::object::object(
	fcppt::log::context &_log_context,
	boost::filesystem::path const &_path
)
:
	log_{
		_log_context,
		sanguis::client::config::log_location(),
		sanguis::log_parameters(
			fcppt::log::name{
				FCPPT_TEXT("settings")
			}
		)
	},
	path_(
		_path
	),
	start_()
{
	FCPPT_LOG_DEBUG(
		log_,
		fcppt::log::_
			<< FCPPT_TEXT("Trying to load settings from ")
			<< fcppt::filesystem::path_to_string(
				_path
			)
	);

	try
	{
		// TODO: Direct initialization
		if(
			sge::parse::ini::parse_file(
				path_,
				start_
			).result_code()
			!=
			sge::parse::result_code::ok
		)
		{
			start_.sections.clear();

			FCPPT_LOG_INFO(
				log_,
				fcppt::log::_
					<< FCPPT_TEXT("Loading the settings failed!")
			);
		}
	}
	catch(
		sge::parse::exception const &_error
	)
	{
		FCPPT_LOG_INFO(
			log_,
			fcppt::log::_
				<< FCPPT_TEXT("Loading the settings failed with: ")
				<< _error.string()
		);
	}
}