|
From: Foster B. <fos...@us...> - 2005-04-18 21:15:57
|
Update of /cvsroot/adobe-source/sandbox/visual_refactor/adobe/test/adam_tutorial In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27679/adobe/test/adam_tutorial Added Files: Jamfile adam_tutorial.mcp adam_tutorial.vcproj default.adm main.cpp Log Message: SO SORRY for the large qty of emails -- creating a branch for Adobe Begin refactoring. --- NEW FILE: main.cpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /*************************************************************************************************/ #include <iostream> #include <boost/config.hpp> #include <boost/filesystem/operations.hpp> #include <boost/filesystem/fstream.hpp> #include <adobe/name.hpp> #include <adobe/value.hpp> #include <adobe/dictionary.hpp> #include <adobe/array.hpp> #include <adobe/adam.hpp> #include <adobe/adam_evaluate.hpp> #include <adobe/adam_parser.hpp> #include <map> /****************************************************************************************************/ namespace bfs = boost::filesystem; /****************************************************************************************************/ namespace { /****************************************************************************************************/ typedef std::map<adobe::name_t, adobe::value_t> cell_set_t; /****************************************************************************************************/ void value_changed(cell_set_t::value_type& cell, const adobe::value_t& new_value) { cell.second = new_value; std::cout << " Adam says: cell \'" << cell.first.get() << "\' updated to value " << cell.second << std::endl; } /****************************************************************************************************/ void setup_monitor(adobe::sheet_t& sheet, cell_set_t::value_type& cell) { sheet.monitor_value(cell.first, boost::bind(value_changed, boost::ref(cell), _1)); } /****************************************************************************************************/ void stream_cell_state(const cell_set_t::value_type& cell) { std::cout << " \'" << cell.first.get() << "\': " << cell.second << std::endl; } /****************************************************************************************************/ struct sheet_tracker { explicit sheet_tracker(const bfs::path& sheet_path) : sheet_m(), callbacks_m(adobe::bind_to_sheet(sheet_m)) { std::string file_path(sheet_path.native_file_string()); std::ifstream sheet_file(file_path.c_str()); callbacks_m.add_cell_proc_m = boost::bind(&sheet_tracker::add_cell_trap, boost::ref(*this), callbacks_m.add_cell_proc_m, _1, _2, _3, _4); callbacks_m.add_interface_proc_m = boost::bind(&sheet_tracker::add_interface_trap, boost::ref(*this), callbacks_m.add_interface_proc_m, _1, _2, _3, _4, _5, _6); if (!sheet_file.is_open()) std::cerr << "Could not open \"" << file_path << "\"!\n"; // set up adam sheet adobe::parse(sheet_file, adobe::line_position_t(), callbacks_m); } void loop(); private: sheet_tracker(); // unimplemented sheet_tracker(const sheet_tracker&); // unimplemented sheet_tracker& operator = (const sheet_tracker&); // unimplemented void add_cell_trap( adobe::adam_callback_suite_t::add_cell_proc_t original, adobe::adam_callback_suite_t::cell_type_t type, adobe::name_t cell_name, const adobe::line_position_t& position, const adobe::array_t& expr_or_init); void add_interface_trap(adobe::adam_callback_suite_t::add_interface_proc_t original, adobe::name_t cell_name, bool linked, const adobe::line_position_t& position1, const adobe::array_t& initializer, const adobe::line_position_t& position2, const adobe::array_t& expression); adobe::sheet_t sheet_m; adobe::adam_callback_suite_t callbacks_m; std::map<adobe::name_t, adobe::value_t> cell_set_m; }; /****************************************************************************************************/ void sheet_tracker::add_cell_trap( adobe::adam_callback_suite_t::add_cell_proc_t original, adobe::adam_callback_suite_t::cell_type_t type, adobe::name_t cell_name, const adobe::line_position_t& position, const adobe::array_t& expr_or_init) { original(type, cell_name, position, expr_or_init, std::string(), std::string()); std::cout << " Adding cell \'" << cell_name.get() << "\' (type " << type << ")" << std::endl; cell_set_m[cell_name] = adobe::value_t(); } /****************************************************************************************************/ void sheet_tracker::add_interface_trap( adobe::adam_callback_suite_t::add_interface_proc_t original, adobe::name_t cell_name, bool linked, const adobe::line_position_t& position1, const adobe::array_t& initializer, const adobe::line_position_t& position2, const adobe::array_t& expression) { original(cell_name, linked, position1, initializer, position2, expression, std::string(), std::string()); std::cout << " Adding interface cell \'" << cell_name.get() << "\'" << std::endl; cell_set_m[cell_name] = adobe::value_t(); } /****************************************************************************************************/ void sheet_tracker::loop() { std::string cell_name_buffer; std::vector<char> new_value_buffer; cell_name_buffer.reserve(1024); new_value_buffer.reserve(1024); new_value_buffer.resize(1); adobe::for_each(cell_set_m, boost::bind(setup_monitor, boost::ref(sheet_m), _1)); while (true) { sheet_m.update(); std::cout << "Current Cell States:" << std::endl; adobe::for_each(cell_set_m, stream_cell_state); std::cout << "Enter in the name of a cell for which you would like to change the value: "; std::cin.getline(&cell_name_buffer[0], 1024); std::cout << "Enter in the new value for cell \'" << &cell_name_buffer[0] << "\': "; std::cin.getline(&new_value_buffer[0], 1024); sheet_m.set(adobe::name_t(&cell_name_buffer[0]), sheet_m.inspect(adobe::parse_adam_expression(&new_value_buffer[0]))); } } /****************************************************************************************************/ } // namespace /****************************************************************************************************/ int main(int argc, char* argv[]) { try { std::cerr << "Compiler: " << BOOST_COMPILER << std::endl; std::cerr << "WARNING: This Adam tutorial only supports numerical cell values!" << std::endl; std::string pathname(argc > 1 ? (argv[1]) : ("./default.adm")); bfs::path filepath(pathname.c_str()); sheet_tracker(filepath).loop(); } catch (const std::exception& doh) { std::cerr << "Exception: " << doh.what() << "\n"; } catch (...) { std::cerr << "Unknown Exception\n"; } } --- NEW FILE: adam_tutorial.vcproj --- <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="7.10" Name="adam_tutorial" ProjectGUID="{F19941BD-A4B3-4940-A24E-D6340F962F54}" Keyword="Win32Proj"> <Platforms> <Platform Name="Win32"/> </Platforms> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="bindebug" IntermediateDirectory="Debug" ConfigurationType="1" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\..\..\adobe\future;..\..\..\third_party\boost_tp\boost;..\..\..\" PreprocessorDefinitions="WIN32;ADOBE_SERIALIZATION=1;BOOST_ALL_NO_LIB=1" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="4"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="asl_lib_dev.lib boost_lib.lib" OutputFile="$(OutDir)/adam_tutorial.exe" LinkIncremental="2" AdditionalLibraryDirectories="..\..\..\adobe\build\boost_lib\bindebug;..\..\..\adobe\build\asl_lib_dev\bindebug" IgnoreAllDefaultLibraries="FALSE" IgnoreDefaultLibraryNames="LIBCMTD" GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(OutDir)/adam_tutorial.pdb" SubSystem="1" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="bin" IntermediateDirectory="Release" ConfigurationType="1" CharacterSet="2"> <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="..\..\..\adobe\future;..\..\..\third_party\boost_tp\boost;..\..\..\" PreprocessorDefinitions="WIN32;ADOBE_SERIALIZATION=1;BOOST_ALL_NO_LIB=1;NDEBUG" RuntimeLibrary="4" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" AdditionalDependencies="asl_lib_dev.lib boost_lib.lib" OutputFile="$(OutDir)/adam_tutorial.exe" LinkIncremental="1" AdditionalLibraryDirectories="..\..\..\adobe\build\boost_lib\bin;..\..\..\adobe\build\asl_lib_dev\bin" IgnoreDefaultLibraryNames="LIBCMTD" GenerateDebugInformation="TRUE" SubSystem="1" OptimizeReferences="2" EnableCOMDATFolding="2" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCXMLDataGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> <Tool Name="VCManagedWrapperGeneratorTool"/> <Tool Name="VCAuxiliaryManagedWrapperGeneratorTool"/> </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="..\..\..\third_party\boost_tp\boost\libs\filesystem\src\convenience.cpp"> </File> <File RelativePath="..\..\..\third_party\boost_tp\boost\libs\filesystem\src\exception.cpp"> </File> <File RelativePath="..\..\future\source\iomanip.cpp"> </File> <File RelativePath="..\..\future\source\iomanip_pdf.cpp"> </File> <File RelativePath=".\main.cpp"> </File> <File RelativePath="..\..\..\third_party\boost_tp\boost\libs\filesystem\src\operations_posix_windows.cpp"> </File> <File RelativePath="..\..\..\third_party\boost_tp\boost\libs\filesystem\src\path_posix_windows.cpp"> </File> </Filter> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> </Filter> <Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: default.adm --- sheet distance_calculator { interface: distance : 15; rate : 3; time : 5; logic: relate { rate <== distance / time; time <== distance / rate; distance <== rate * time; } } --- NEW FILE: Jamfile --- import testing ; project adobe/adam_tutorial : requirements <link>static ; exe "adam_tutorial" : main.cpp /adobe//asl_lib_dev /boost/filesystem//boost_filesystem ; --- NEW FILE: adam_tutorial.mcp --- (This appears to be a binary file; contents omitted.) |