summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/statechart/example/Keyboard
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/statechart/example/Keyboard
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/statechart/example/Keyboard')
-rw-r--r--src/boost/libs/statechart/example/Keyboard/Keyboard.cpp182
-rw-r--r--src/boost/libs/statechart/example/Keyboard/Keyboard.vcproj284
2 files changed, 466 insertions, 0 deletions
diff --git a/src/boost/libs/statechart/example/Keyboard/Keyboard.cpp b/src/boost/libs/statechart/example/Keyboard/Keyboard.cpp
new file mode 100644
index 00000000..e9f08672
--- /dev/null
+++ b/src/boost/libs/statechart/example/Keyboard/Keyboard.cpp
@@ -0,0 +1,182 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright 2002-2006 Andreas Huber Doenni
+// Distributed under the Boost Software License, Version 1.0. (See accompany-
+// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//////////////////////////////////////////////////////////////////////////////
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+// The following example program demonstrates the use of orthogonal states and
+// state_downcast to query the state of orthogonal regions.
+// Moreover, the use of the state type information interface is also shown.
+//////////////////////////////////////////////////////////////////////////////
+// #define BOOST_STATECHART_USE_NATIVE_RTTI
+
+
+#include <boost/statechart/event.hpp>
+#include <boost/statechart/state_machine.hpp>
+#include <boost/statechart/simple_state.hpp>
+#include <boost/statechart/transition.hpp>
+#include <boost/statechart/custom_reaction.hpp>
+
+#include <boost/mpl/list.hpp>
+#include <boost/config.hpp>
+
+#include <iostream>
+#include <iomanip>
+
+#ifdef BOOST_INTEL
+# pragma warning( disable: 304 ) // access control not specified
+# pragma warning( disable: 981 ) // operands are evaluated in unspecified order
+#endif
+
+
+
+namespace sc = boost::statechart;
+namespace mpl = boost::mpl;
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+struct EvNumLockPressed : sc::event< EvNumLockPressed > {};
+struct EvCapsLockPressed : sc::event< EvCapsLockPressed > {};
+struct EvScrollLockPressed : sc::event< EvScrollLockPressed > {};
+struct EvRequestShutdown : sc::event< EvRequestShutdown > {};
+
+struct Active;
+struct Keyboard : sc::state_machine< Keyboard, Active > {};
+
+struct NumLockOff;
+struct CapsLockOff;
+struct ScrollLockOff;
+struct Active: sc::simple_state<
+ Active, Keyboard, mpl::list< NumLockOff, CapsLockOff, ScrollLockOff > >
+{
+ typedef sc::custom_reaction< EvRequestShutdown > reactions;
+
+ sc::result react( const EvRequestShutdown & );
+};
+
+ struct NumLockOn : sc::simple_state< NumLockOn, Active::orthogonal< 0 > >
+ {
+ typedef sc::transition< EvNumLockPressed, NumLockOff > reactions;
+ };
+
+ struct NumLockOff : sc::simple_state< NumLockOff, Active::orthogonal< 0 > >
+ {
+ typedef sc::transition< EvNumLockPressed, NumLockOn > reactions;
+ };
+
+ struct CapsLockOn : sc::simple_state< CapsLockOn, Active::orthogonal< 1 > >
+ {
+ typedef sc::transition< EvCapsLockPressed, CapsLockOff > reactions;
+ };
+
+ struct CapsLockOff : sc::simple_state< CapsLockOff, Active::orthogonal< 1 > >
+ {
+ typedef sc::transition< EvCapsLockPressed, CapsLockOn > reactions;
+ };
+
+ struct ScrollLockOn : sc::simple_state< ScrollLockOn, Active::orthogonal< 2 > >
+ {
+ typedef sc::transition< EvScrollLockPressed, ScrollLockOff > reactions;
+ };
+
+ struct ScrollLockOff : sc::simple_state< ScrollLockOff, Active::orthogonal< 2 > >
+ {
+ typedef sc::transition< EvScrollLockPressed, ScrollLockOn > reactions;
+ };
+
+sc::result Active::react( const EvRequestShutdown & )
+{
+ if ( ( state_downcast< const NumLockOff * >() != 0 ) &&
+ ( state_downcast< const CapsLockOff * >() != 0 ) &&
+ ( state_downcast< const ScrollLockOff * >() != 0 ) )
+ {
+ std::cout << "Shutdown request accepted\n";
+ return terminate();
+ }
+ else
+ {
+ std::cout << "Ignoring shutdown request\n\n";
+ return discard_event();
+ }
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+void DisplayStateConfiguration( const Keyboard & keyboard )
+{
+ char orthogonalRegion = 'a';
+
+ for ( Keyboard::state_iterator pLeafState = keyboard.state_begin();
+ pLeafState != keyboard.state_end(); ++pLeafState )
+ {
+ std::cout << "Orthogonal region " << orthogonalRegion << ": ";
+
+ const Keyboard::state_base_type * pState = &*pLeafState;
+
+ while ( pState != 0 )
+ {
+ if ( pState != &*pLeafState )
+ {
+ std::cout << " -> ";
+ }
+
+ #ifdef BOOST_STATECHART_USE_NATIVE_RTTI
+ std::cout << std::setw( 15 ) << typeid( *pState ).name();
+ #else
+ std::cout << std::setw( 15 ) <<
+ pState->custom_dynamic_type_ptr< char >();
+ #endif
+ pState = pState->outer_state_ptr();
+ }
+
+ std::cout << "\n";
+ ++orthogonalRegion;
+ }
+
+ std::cout << "\n";
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ #ifndef BOOST_STATECHART_USE_NATIVE_RTTI
+ Active::custom_static_type_ptr( "Active" );
+ NumLockOn::custom_static_type_ptr( "NumLockOn" );
+ NumLockOff::custom_static_type_ptr( "NumLockOff" );
+ CapsLockOn::custom_static_type_ptr( "CapsLockOn" );
+ CapsLockOff::custom_static_type_ptr( "CapsLockOff" );
+ ScrollLockOn::custom_static_type_ptr( "ScrollLockOn" );
+ ScrollLockOff::custom_static_type_ptr( "ScrollLockOff" );
+ #endif
+
+ std::cout << "Boost.Statechart Keyboard example\n\n";
+ Keyboard keyboard;
+ keyboard.initiate();
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvNumLockPressed() );
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvRequestShutdown() );
+ keyboard.process_event( EvCapsLockPressed() );
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvRequestShutdown() );
+ keyboard.process_event( EvScrollLockPressed() );
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvRequestShutdown() );
+
+ keyboard.process_event( EvNumLockPressed() );
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvRequestShutdown() );
+ keyboard.process_event( EvCapsLockPressed() );
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvRequestShutdown() );
+ keyboard.process_event( EvScrollLockPressed() );
+ DisplayStateConfiguration( keyboard );
+ keyboard.process_event( EvRequestShutdown() );
+
+ return 0;
+}
diff --git a/src/boost/libs/statechart/example/Keyboard/Keyboard.vcproj b/src/boost/libs/statechart/example/Keyboard/Keyboard.vcproj
new file mode 100644
index 00000000..9ce6ac0a
--- /dev/null
+++ b/src/boost/libs/statechart/example/Keyboard/Keyboard.vcproj
@@ -0,0 +1,284 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="Keyboard"
+ ProjectGUID="{4CBF564B-EEC6-49E1-B69B-CABF5DDFC684}"
+ RootNamespace="Keyboard"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ ExceptionHandling="1"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ BufferSecurityCheck="true"
+ DisableLanguageExtensions="true"
+ TreatWChar_tAsBuiltInType="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ WarnAsError="true"
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/Keyboard.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile="$(OutDir)/Keyboard.pdb"
+ SubSystem="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="3"
+ InlineFunctionExpansion="2"
+ AdditionalIncludeDirectories="..\..\..\.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="true"
+ ExceptionHandling="1"
+ RuntimeLibrary="2"
+ BufferSecurityCheck="false"
+ EnableFunctionLevelLinking="true"
+ DisableLanguageExtensions="true"
+ TreatWChar_tAsBuiltInType="true"
+ ForceConformanceInForLoopScope="true"
+ RuntimeTypeInfo="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="4"
+ WarnAsError="true"
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/Keyboard.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="false"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\Keyboard.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Statechart Header Files"
+ >
+ <File
+ RelativePath="..\..\..\..\boost\statechart\asynchronous_state_machine.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\custom_reaction.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\deep_history.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\deferral.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\event.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\event_base.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\event_processor.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\exception_translator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\fifo_scheduler.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\in_state_reaction.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\null_exception_translator.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\result.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\shallow_history.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\simple_state.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\state.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\state_machine.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\termination.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\boost\statechart\transition.hpp"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>