//===========================================================================// // File: Matcher.hpp // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 02/18/98 ECH Authored // //---------------------------------------------------------------------------// // Copyright (C) 1994-1998, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #pragma once #include "Adept.hpp" #include "Channel.hpp" #include "ComponentWeb.hpp" namespace Adept { //########################################################################## //######################## MatcherChannel ############################ //########################################################################## template class MatcherOf: public ChannelOf { public: static void InitializeClass(); static void TerminateClass(); typedef ChannelOf BaseClass; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Constructor/Destructor // public: ~MatcherOf(); static MatcherOf* Create( MemoryStream *stream, ComponentWeb *owning_web ); protected: MatcherOf( ClassData *class_data, MemoryStream *stream, ComponentWeb *owning_web ); void SkipStreamData(MemoryStream *stream); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Virtual data // public: static ClassData *DefaultData; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Component execution // public: void ChannelChanged(Channel *channel); protected: T matchValue; int matchCommand, missCommand; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Tool Support // public: static ClassData* CreateFactoryRequest(FactoryRequestParameters *parameters); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Test support // public: void TestInstance(); }; // // Class Data Support // template ChannelOf::ClassData* MatcherOf::DefaultData = NULL; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // template void MatcherOf::TerminateClass() { Unregister_Object(DefaultData); delete DefaultData; DefaultData = NULL; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // template MatcherOf::~MatcherOf() { } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // template MatcherOf::MatcherOf( ClassData *class_data, MemoryStream *stream, ComponentWeb *owning_web ): ChannelOf(class_data, stream, owning_web) { *stream >> matchValue >> matchCommand >> missCommand; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // template void MatcherOf::SkipStreamData(MemoryStream *stream) { Check_Object(this); Check_Object(stream); BaseClass::SkipStreamData(stream); stream->AdvancePointer(sizeof(T) + sizeof(int) + sizeof(int)); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // template void MatcherOf::ChannelChanged(Channel *channel) { Check_Object(this); Check_Object(channel); ChannelOf* input = Cast_Object(ChannelOf*, channel); channelOutput = input->ReadChannel(); if (Close_Enough(channelOutput, matchValue)) { if (matchCommand != -1) { channelCommand = matchCommand; NotifyDependantsOfChange(); } } else { if (missCommand != -1) { channelCommand = missCommand; NotifyDependantsOfChange(); } } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // template void MatcherOf::TestInstance() { Verify(IsDerivedFrom(DefaultData)); } }