Posts

Observer(Event) system (Signals and Slots), type and template based

Image
0 Signals are represented as types. You can connect a member function of some instance to the Observer system. This connected function will be called whenever a signal of a type that is the same type as the function parameter is emitted. ObserverSystem.hpp: #include <vector> class ObserverSystem { public: template<typename SignalType> inline static void emitSignal(const SignalType& signal) { for(auto f : callEverything<SignalType>) { f(signal); } } template<typename SignalType, typename ObjectType> inline static void connect(ObjectType& object, void (ObjectType::*function)(const SignalType& signal)) { bool add = true; for(auto& entry : functions<SignalType, ObjectType>) ...

Selecting correct carton based on qty

Image
2 I'm attempting to create a function that will select the correct carton based on the qty of the carton content. Here are my cartons that have the number of items they can hold: SMALL_PASCAL = 300 BIG_PASCAL = 600 BABY_BOX = 1200 A485_1201 = 1800 A4140_1901 = 3000 A485 = 5000 And here is the method that will return the CartonType : /// <summary> /// Get Carton Type /// </summary> /// <param name="qty"></param> /// <returns></returns> [Test] private static CartonType GetCartonType(int qty) { if (qty <= 300) { return CartonType.SMALL_PASCAL; } else if (qty > 300 && qty <= 600) { return CartonType.SMALL_PASCAL; } else if (qty > 600 && qty <= 1200) { ...