Skip to content

Commit

Permalink
Define handlers with std::array
Browse files Browse the repository at this point in the history
  • Loading branch information
frmdstryr committed Jan 22, 2025
1 parent 05967c0 commit 6797be7
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 28 deletions.
4 changes: 1 addition & 3 deletions atom/src/defaultvaluebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ typedef PyObject*
( *handler )( Member* member, CAtom* atom );


static handler
handlers[] = {
static const std::array<handler, DefaultValue::Mode::Last> handlers = {
no_op_handler,
static_handler,
list_handler,
Expand All @@ -205,7 +204,6 @@ handlers[] = {
member_method_object_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == DefaultValue::Mode::Last, "Handler missing" );

} // namespace

Expand Down
5 changes: 1 addition & 4 deletions atom/src/delattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ typedef int
( *handler )( Member* member, CAtom* atom );


static handler
handlers[] = {
static const std::array<handler, DelAttr::Mode::Last> handlers = {
no_op_handler,
slot_handler,
constant_handler,
Expand All @@ -192,8 +191,6 @@ handlers[] = {
property_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == DelAttr::Mode::Last, "Handler missing" );


} // namespace

Expand Down
4 changes: 1 addition & 3 deletions atom/src/getattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ typedef PyObject*
( *handler )( Member* member, CAtom* atom );


static handler
handlers[] = {
static const std::array<handler, GetAttr::Mode::Last> handlers = {
no_op_handler,
slot_handler,
event_handler,
Expand All @@ -259,7 +258,6 @@ handlers[] = {
member_method_object_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == GetAttr::Mode::Last, "Handler missing" );

} // namespace

Expand Down
4 changes: 1 addition & 3 deletions atom/src/getstatebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ typedef PyObject*
( *handler )( Member* member, CAtom* atom );


static handler
handlers[] = {
static const std::array<handler, GetState::Mode::Last> handlers = {
include_handler, // We want the include handler to be the default one
exclude_handler,
include_non_default_handler,
Expand All @@ -127,7 +126,6 @@ handlers[] = {
member_method_object_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == GetState::Mode::Last, "Handler missing" );

} // namespace

Expand Down
1 change: 1 addition & 0 deletions atom/src/member.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
|----------------------------------------------------------------------------*/
#pragma once

#include <array>
#include <vector>
#include <cppy/cppy.h>
#include "inttypes.h"
Expand Down
4 changes: 1 addition & 3 deletions atom/src/postgetattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,14 @@ typedef PyObject*
( *handler )( Member* member, CAtom* atom, PyObject* value );


static handler
handlers[] = {
static const std::array<handler, PostGetAttr::Mode::Last> handlers = {
no_op_handler,
delegate_handler,
object_method_value_handler,
object_method_name_value_handler,
member_method_object_value_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == PostGetAttr::Mode::Last, "Handler missing" );

} // namespace

Expand Down
4 changes: 1 addition & 3 deletions atom/src/postsetattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,14 @@ typedef int
( *handler )( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue );


static handler
handlers[] = {
static const std::array<handler, PostSetAttr::Mode::Last> handlers = {
no_op_handler,
delegate_handler,
object_method_old_new_handler,
object_method_name_old_new_handler,
member_method_object_old_new_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == PostSetAttr::Mode::Last, "Handler missing" );

} // namespace

Expand Down
4 changes: 1 addition & 3 deletions atom/src/postvalidatebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,14 @@ typedef PyObject*
( *handler )( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue );


static handler
handlers[] = {
static const std::array<handler, PostValidate::Mode::Last> handlers = {
no_op_handler,
delegate_handler,
object_method_old_new_handler,
object_method_name_old_new_handler,
member_method_object_old_new_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == PostValidate::Mode::Last, "Handler missing" );

} // namespace

Expand Down
4 changes: 1 addition & 3 deletions atom/src/setattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ typedef int
( *handler )( Member* member, CAtom* atom, PyObject* value );


static handler
handlers[] = {
static const std::array<handler, SetAttr::Mode::Last> handlers = {
no_op_handler,
slot_handler,
constant_handler,
Expand All @@ -380,7 +379,6 @@ handlers[] = {
member_method_object_value_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == SetAttr::Mode::Last, "Handler missing" );

} // namespace

Expand Down
4 changes: 1 addition & 3 deletions atom/src/validatebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,7 @@ typedef PyObject*
( *handler )( Member* member, CAtom* atom, PyObject* oldvalue, PyObject* newvalue );


static handler
handlers[] = {
static const std::array<handler, Validate::Mode::Last> handlers = {
no_op_handler,
bool_handler,
long_handler,
Expand Down Expand Up @@ -1000,7 +999,6 @@ handlers[] = {
member_method_object_old_new_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == Validate::Mode::Last, "Handler missing" );

} // namespace

Expand Down

0 comments on commit 6797be7

Please sign in to comment.