noxrepo / nox

The NOX Controller
Other
139 stars 85 forks source link

Does the function has_factory work correctly? #24

Closed Jinhui-Wu closed 10 years ago

Jinhui-Wu commented 10 years ago

In the head file openflow-inl-1.0.hh // Factory template struct has_factory { // template static char test(typeof(&C::factory)); template static char test(typeof(&C::factory())); // something wrong? template static long test(...);

public: enum { value = sizeof(test(0)) == sizeof(char) }; };

All the openflow message class inherit from v1::ofp_msg which has a member function -- factory(), so has_factory will always return TRUE. Am I correct? I find this problem when I fail to send v1::ofp_port_stats_request.

tootoonchian commented 10 years ago

There I used a C++ template technique called SFINAE (http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error) to detect the types that have subclasses in order to construct and deserialize the correct openflow message subclass. (has_factory will only be instantiated for such types and thus the correct construct_and_load struct will be selected.)