Example #1
0
void test_for_each() {
	int idx = 0;
	for ( const auto &it: enum_info<myenum0>::values ) {
		switch ( idx ) {
			case 0: MY_ASSERT(
				0         == strcmp(it.name, "myenum0::member0") &&
				0         == strcmp("myenum0::member0", enum_cast(it.value)) &&
				it.ivalue == static_cast<enum_info<myenum0>::underlying_type>(it.value) &&
				0         == it.ivalue
			);
			break;
			case 1: MY_ASSERT(
				0         == strcmp(it.name, "myenum0::member1") &&
				0         == strcmp("myenum0::member1", enum_cast(it.value)) &&
				it.ivalue == static_cast<enum_info<myenum0>::underlying_type>(it.value) &&
				1         == it.ivalue
			);
			break;
			case 2: MY_ASSERT(
				0         == strcmp(it.name, "myenum0::member2") &&
				0         == strcmp("myenum0::member2", enum_cast(it.value)) &&
				it.ivalue == static_cast<enum_info<myenum0>::underlying_type>(it.value) &&
				2         == it.ivalue
			);
			break;
			default: MY_ASSERT(0)
		}
		++idx;
	}

	std::cout << "test_for_each() PASSED" << std::endl;
}
Example #2
0
	/**
		Test whether the geometry fills expand area along any
		specified axes.

		@param axes Axes to test.
		@param equal Whether the fill axes should match exactly.
	*/
	bool
	fills(
		Axis const axes,
		bool const equal = false
	) const noexcept {
		return
			equal
			? axes == fill()
			: enum_cast(axes) & enum_cast(fill())
		;
	}
Example #3
0
	/**
		Test whether the geometry expands along any specified axes.

		@param axes Axes to test.
		@param equal Whether the axes should match exactly.
	*/
	bool
	expands(
		Axis const axes,
		bool const equal = false
	) const noexcept {
		return
			equal
			? axes == expand()
			: enum_cast(axes) & enum_cast(expand())
		;
	}
Example #4
0
void test_cast_to_char() {
	MY_ASSERT(0 == strcmp("myenum1::member2", enum_cast(myenum1::member2)));
	MY_ASSERT(0 == strcmp("myenum2::member5", enum_cast(myenum2::member5)));
	MY_ASSERT(0 == strcmp("myenum3::member8", enum_cast(myenum3::member8)));
	MY_ASSERT(0 == strcmp("myenum4::member11", enum_cast(myenum4::member11)));
	MY_ASSERT(0 == strcmp("myenum5::member13", enum_cast(myenum5::member13)));

	MY_ASSERT(0 == strcmp("member2", enum_cast(myenum1::member2, false)));
	MY_ASSERT(0 == strcmp("member5", enum_cast(myenum2::member5, false)));
	MY_ASSERT(0 == strcmp("member8", enum_cast(myenum3::member8, false)));
	MY_ASSERT(0 == strcmp("member11", enum_cast(myenum4::member11, false)));
	MY_ASSERT(0 == strcmp("member13", enum_cast(myenum5::member13, false)));

	std::cout << "test_cast_to_char() PASSED" << std::endl;
}
Example #5
0
void
BasicGrid::render_impl(
	UI::Widget::RenderData& rd
) noexcept {
	UI::GridRenderData grid_rd{
		rd,
		is_focused(),
		is_focused()
	};
	render_view(
		grid_rd,
		!enum_cast(queued_actions() & UI::UpdateActions::flag_noclear)
	);

	auto const& view = this->view();
	Rect const empty_frame{
		{view.content_frame.pos.x, view.content_frame.pos.y + view.row_count},
		{
			view.content_frame.size.width,
			max_ce(0, view.fit_count - view.row_count)
		}
	};
	if (0 < empty_frame.size.height) {
		grid_rd.rd.terminal.clear_back(empty_frame);
		grid_rd.rd.terminal.put_line(
			empty_frame.pos,
			empty_frame.size.height,
			Axis::vertical,
			tty::make_cell('~',
				tty::Color::blue | tty::Attr::bold,
				tty::Color::term_default
			)
		);
	}
}
Example #6
0
void
Session::notify_complete_impl(
	Hord::Cmd::UnitBase const& command,
	Hord::Cmd::TypeInfo const& type_info
) noexcept {
	static const char* const
	result_names[]{
		"success",
		"success_no_action",
		"error",
	};

	Log::acquire(command.bad() ? Log::error : Log::debug)
		<< "notify_complete: "
		<< std::hex << type_info.id
		<< ' ' << type_info.name
		<< ", result: " << result_names[enum_cast(command.result())]
		<< ", message: \"" << command.message() << '\"'
		<< '\n'
	;

	// Notify views of failed or mutative command execution
	if (m_view && (command.bad() || command.ok_action())) {
		m_view->notify_command(nullptr, command, type_info);
	}
}
Example #7
0
	/**
		Set fill axes.

		@param axes Fill axes.
	*/
	void
	set_fill(
		Axis const axes
	) noexcept {
		m_flags.set_masked(
			Flags::fill_mask,
			static_cast<Flags>(enum_cast(axes) << fill_shift)
		);
	}
Example #8
0
	/**
		Set expand axes.

		@param axes Expand axes.
	*/
	void
	set_expand(
		Axis const axes
	) noexcept {
		m_flags.set_masked(
			Flags::expand_mask,
			static_cast<Flags>(enum_cast(axes) << expand_shift)
		);
	}
Example #9
0
		Entry(
			duct::VarTemplate&& tpl,
			Flags const flags = Flags::none
		)
			: flags(flags)
			, tpl(std::move(tpl))
			, value(
				enum_cast(flags & Flags::collect)
				? duct::VarType::node
				: duct::VarType::null
			)
		{}
Example #10
0
namespace Beard {

namespace {
static char const
s_error_invalid[]{BEARD_STR_LIT("INVALID")},
* const s_error_names[]{
	BEARD_STR_LIT("unknown"),

// serialization
	BEARD_STR_LIT("serialization_io_failed"),
	BEARD_STR_LIT("serialization_data_malformed"),

// tty
	BEARD_STR_LIT("tty_terminal_already_open"),
	BEARD_STR_LIT("tty_terminal_info_uninitialized"),
	BEARD_STR_LIT("tty_sigwinch_handler_already_active"),
	BEARD_STR_LIT("tty_sigaction_failed"),
	BEARD_STR_LIT("tty_device_open_failed"),
	BEARD_STR_LIT("tty_invalid_fd"),

	BEARD_STR_LIT("tty_init_failed"),

// ui
	BEARD_STR_LIT("ui_invalid_property"),
	BEARD_STR_LIT("ui_invalid_group"),
	BEARD_STR_LIT("ui_property_not_found"),

	BEARD_STR_LIT("ui_context_already_open"),

	BEARD_STR_LIT("ui_container_null_widget"),
};
} // anonymous namespace

static_assert(
	enum_cast(ErrorCode::LAST)
	== std::extent<decltype(s_error_names)>::value,
	"ErrorCode name list is incomplete"
);

char const*
get_error_name(
	ErrorCode const error_code
) noexcept {
	std::size_t const index = static_cast<std::size_t>(error_code);
	if (index < std::extent<decltype(s_error_names)>::value) {
		return s_error_names[index];
	} else {
		return s_error_invalid;
	}
}

} // namespace Beard
Example #11
0
	/**
		Assign prop state.

		@note If the prop is not supplied, this has no effect.

		@par
		@note IO::PropState::unsupplied is masked out
		of @a state before assignment. Only the constructor can
		assign this state.

		@returns @c *this.
	*/
	PropStateStore&
	assign(
		IO::PropType const prop_type,
		IO::PropState const state
	) noexcept {
		if (supplies(prop_type)) {
			m_states
				= mask_off(m_states, prop_type)
				| shift_up(
					~prop_unsupplied_single & enum_cast(state),
					prop_type
				)
			;
		}
		return *this;
	}
Example #12
0
	const Dojo::TexFormatInfo& TexFormatInfo::getFor(PixelFormat format) {
		static const TexFormatInfo GLFormat[] = {
			{ 4, GL_RGBA8, GL_UNSIGNED_BYTE,					4, GL_RGBA, GL_UNSIGNED_BYTE, true },
			{ 3, GL_RGB8, GL_UNSIGNED_BYTE,					3, GL_RGB, GL_UNSIGNED_BYTE, false },
			{ 2, GL_RGB8, GL_UNSIGNED_SHORT_5_6_5,		    3, GL_RGB, GL_UNSIGNED_BYTE, false },
			{ 4, GL_RGBA8, GL_UNSIGNED_INT_2_10_10_10_REV,	4, GL_RGBA, GL_UNSIGNED_BYTE,  true },
			{ 4, GL_SRGB8_ALPHA8, GL_UNSIGNED_BYTE,			4, GL_RGBA, GL_UNSIGNED_BYTE, true },
			{ 3, GL_SRGB8, GL_UNSIGNED_BYTE,				3, GL_RGB, GL_UNSIGNED_BYTE, false },
			{ 8, GL_RGBA16F, GL_HALF_FLOAT,					16, GL_RGBA, GL_FLOAT, false },
			{ 1, GL_R8, GL_UNSIGNED_BYTE,					1, GL_RED, GL_UNSIGNED_BYTE, false },
			{ 2, GL_RG8, GL_UNSIGNED_BYTE,					2, GL_RG, GL_UNSIGNED_BYTE, false },
			{ 1, GL_R8, GL_UNSIGNED_BYTE,					1, GL_ALPHA, GL_UNSIGNED_BYTE, true },
			{ 0, 0, 0, 0, 0 },
		};

		return GLFormat[enum_cast(format)];
	}
Example #13
0
void MainEmuFrame::UpdateIsoSrcSelection()
{
	MenuIdentifiers cdsrc = MenuId_Src_Iso;

	switch( g_Conf->CdvdSource )
	{
		case CDVD_SourceType::Iso:		cdsrc = MenuId_Src_Iso;		break;
		case CDVD_SourceType::Plugin:	cdsrc = MenuId_Src_Plugin;	break;
		case CDVD_SourceType::NoDisc:	cdsrc = MenuId_Src_NoDisc;	break;

		jNO_DEFAULT
	}
	sMenuBar.Check( cdsrc, true );
	m_statusbar.SetStatusText( CDVD_SourceLabels[enum_cast(g_Conf->CdvdSource)], 1 );

	EnableCdvdPluginSubmenu( cdsrc == MenuId_Src_Plugin );

	//sMenuBar.SetLabel( MenuId_Src_Iso, wxsFormat( L"%s -> %s", _("Iso"),
	//	exists ? Path::GetFilename(g_Conf->CurrentIso).c_str() : _("Empty") ) );
}
 void  format(CharArray<ENC,LEN>& txt, const encoding_char_t<ENC>* str, LocaleId locale = LocaleId::Neutral) const
 {
   // Format date according to user settings
   if (!WinAPI<ENC>::getDateFormat(locale, enum_cast(zero<DateFlags>()), base_cast(this), str, txt.buffer(), LEN))
     throw platform_error(HERE, "Unable to format date");
 }
 void  format(CharArray<ENC,LEN>& txt, DateFlags flags, LocaleId locale = LocaleId::Neutral) const
 { 
   // Format date according to user settings
   if (!WinAPI<ENC>::getDateFormat(locale, enum_cast(flags), base_cast(this), nullptr, txt.buffer(), LEN))
     throw platform_error(HERE, "Unable to format date");
 }