Exemple #1
0
sanguis::tiles::impl::optional_orientation
sanguis::tiles::impl::decode_name(
	fcppt::string const &_name
)
{
	return
		_name.size()
		!=
		fcppt::enum_size<
			sanguis::tiles::direction
		>::value
		?
			sanguis::tiles::impl::optional_orientation()
		:
			fcppt::algorithm::fold(
				fcppt::make_enum_range<
					sanguis::tiles::direction
				>(),
				sanguis::tiles::impl::optional_orientation(
					sanguis::tiles::orientation::null()
				),
				[
					&_name
				](
					sanguis::tiles::direction const _dir,
					sanguis::tiles::impl::optional_orientation const _state
				)
				{
					return
						fcppt::optional::bind(
							_state,
							[
								_dir,
								&_name
							](
								sanguis::tiles::orientation const _orientation
							)
							{
								typedef
								fcppt::optional::object<
									bool
								>
								optional_bool;

								auto const char_to_bool(
									[](
										fcppt::char_type const _value
									)
									-> optional_bool
									{
										switch(
											_value
										)
										{
										case FCPPT_TEXT('0'):
											return
												optional_bool(
													true
												);
										case FCPPT_TEXT('1'):
											return
												optional_bool(
													false
												);
										}

										return
											optional_bool();
									}
								);

								return
									fcppt::optional::map(
										char_to_bool(
											_name[
												fcppt::cast::enum_to_int<
													fcppt::string::size_type
												>(
													_dir
												)
											]
										),
										[
											_orientation,
											_dir
										](
											bool const _value
										)
										-> sanguis::tiles::orientation
										{
											return
												_value
												?
													_orientation
													|
													_dir
												:
													_orientation
												;
										}
									);
							}
						);
				}
			);
}