stlab.adobe.com Adobe Systems Incorporated

adam.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2008 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_ADAM_HPP
00010 #define ADOBE_ADAM_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <functional>
00015 
00016 #include <boost/utility.hpp>
00017 #include <boost/function.hpp>
00018 
00019 #ifdef __MWERKS__
00020     #pragma warn_unusedarg off
00021     #pragma warn_unusedvar off
00022 #endif
00023 
00024 #include <boost/signals.hpp>
00025 
00026 #ifdef __MWERKS__
00027     #pragma warn_unusedarg reset
00028     #pragma warn_unusedvar reset
00029 #endif
00030 
00031 #include <adobe/any_regular_fwd.hpp>
00032 #include <adobe/array.hpp>
00033 #include <adobe/dictionary_fwd.hpp>
00034 #include <adobe/istream.hpp>
00035 #include <adobe/move.hpp>
00036 #include <adobe/name_fwd.hpp>
00037 #include <adobe/virtual_machine.hpp>
00038 
00039 /*
00040 
00041     REVISIT (sparent) : It would be best to detangle the sheet from
00042     the virtual machine. The way to do this is to allow for funciton
00043     objects to be passed instead of line positions and expression
00044     arrays. The function object could bind to the line_position_t and
00045     the array.... This would allow for easier programatic driving -
00046     however, one would have to construct condition objects which
00047     tracked dependencies and the sheet would require a get() method to
00048     retrieve the value of a cell.
00049 
00050 */
00051 
00052 /*************************************************************************************************/
00053 
00054 namespace adobe {
00055 
00064 /*************************************************************************************************/
00065 
00072 class sheet_t : boost::noncopyable
00073 {
00074  public:
00075     struct relation_t;
00076     
00077     typedef boost::function<void (bool)>                 monitor_invariant_t;
00078     typedef boost::function<void (const any_regular_t&)> monitor_value_t;
00079     typedef boost::function<void (const dictionary_t&)>  monitor_contributing_t;
00080     typedef boost::function<void (bool)>                 monitor_enabled_t;
00081                                                            
00095     typedef boost::signals::connection                   connection_t;
00096      
00097  #if !defined(ADOBE_NO_DOCUMENTATION)
00098     sheet_t();
00099     ~sheet_t();
00100  #endif
00101  
00109     any_regular_t inspect(const array_t& expression);
00110 
00117     void set(name_t cell, const any_regular_t& value); // input cell.
00118 
00140     void touch(const name_t* first, const name_t* last); // range of input cells.
00141     
00150     any_regular_t get(name_t cell);
00151     
00163     void add_input      (name_t name, const line_position_t& position, const array_t& initializer);
00164 
00177     void add_output     (name_t name, const line_position_t& position, const array_t& expression);
00178 
00179 
00190     void add_constant   (name_t name, const line_position_t& position, const array_t& initializer);
00191 
00203     void add_logic      (name_t name, const line_position_t& position, const array_t& expression);
00204 
00216     void add_invariant  (name_t name, const line_position_t& position, const array_t& expression);
00217 
00238     void add_interface  (name_t name, bool linked, const line_position_t& position1,
00239                          const array_t& initializer, const line_position_t& position2, 
00240                          const array_t& expression);
00241     
00242 
00264     void add_relation(const line_position_t& position, const array_t& conditional,
00265                       const relation_t* first, const relation_t* last);
00266 
00267 
00282     connection_t monitor_value(name_t name, const monitor_value_t& proc);
00283 
00305     connection_t monitor_contributing(name_t cell, const dictionary_t& mark, 
00306                                       const monitor_contributing_t& proc);
00307     // output only
00308 
00361     connection_t monitor_enabled(name_t cell, const name_t* first, const name_t* last,
00362                                     const monitor_enabled_t& proc); // input only
00363 
00364     #if 0
00365     connection_t monitor_invariant_contributing(name_t input, const monitor_invariant_t&);
00366     #endif
00367 
00384     connection_t monitor_invariant_dependent(name_t output, const monitor_invariant_t& proc);
00385 
00386 
00397     bool has_input(name_t name) const;
00398 
00409     bool has_output(name_t name) const;
00410 
00411 
00419     void update();
00420     
00429     void reinitialize();
00430 
00431 
00440     void set(const dictionary_t& dictionary); 
00441     
00442     #if 0
00443     dictionary_t current_mark() const;
00444     #endif
00445 
00446 
00454     dictionary_t contributing(const dictionary_t& mark) const;
00455 
00462     dictionary_t contributing() const;
00463     
00467     dictionary_t contributing_to_cell(name_t) const;
00468 
00469     /*
00470         REVISIT (fbrereto) : From a note from sparent 2007/04/13:
00471 
00472         "Make the adam VM public - eventually I'm going to pull it out all
00473         together (The property model library won't directly depend on it -
00474         only function object - which can be implemented with the VM)."
00475 
00476         This solution is a bit hackish, but is a viable intermediary solution;
00477         because sheet_t and its underlying implementation are noncopyable, the
00478         machine can be stored here and held by reference by the implementation,
00479         and everything is fine. Nevertheless, this is an interim solution given
00480         Sean's plans for the VM's relationship to sheet_t in the future.
00481     */
00482     virtual_machine_t machine_m;
00483 
00484  private:
00485     class implementation_t;
00486     implementation_t* object_m;
00487 };
00488 
00489 /*************************************************************************************************/
00490 
00497 struct set_monitor_t : std::unary_function<any_regular_t, void>
00498 {
00499     set_monitor_t(sheet_t& sheet, name_t cell_name) :
00500         cell_name_m(cell_name),
00501         sheet_m(sheet)
00502     { }
00503     
00504     void operator()(const any_regular_t& x)
00505     { sheet_m.get().set(cell_name_m, x); }
00506     
00507  private:
00508     name_t                               cell_name_m;
00509     boost::reference_wrapper<sheet_t>    sheet_m;
00510 };
00511 
00512 /*************************************************************************************************/
00513 
00514 /*
00515     REVISIT (sparent) : line_position_t and array_t need to go in favor of a function object.
00516 */
00517 
00523 struct sheet_t::relation_t
00524 {
00525     relation_t() { }
00526     relation_t(name_t n, line_position_t p, array_t e) :
00527         name_m(n),
00528         position_m(p),
00529         expression_m(move(e))
00530     { }
00531     
00532     friend void swap(relation_t& x, relation_t& y)
00533     {
00534         swap(x.name_m, y.name_m);
00535         swap(x.position_m, y.position_m);
00536         swap(x.expression_m, y.expression_m);
00537     }
00538     
00539     relation_t(move_from<relation_t> x) :
00540         name_m(x.source.name_m),
00541         position_m(x.source.position_m),
00542         expression_m(move(x.source.expression_m))
00543     { }
00544     
00545     relation_t& operator=(relation_t x) 
00546     { swap(*this, x); return *this; }
00547 
00548 
00549     name_t          name_m;
00550     line_position_t position_m;
00551     array_t         expression_m;
00552 };
00553 
00554 /*************************************************************************************************/
00555     
00556 } // namespace adobe
00557 
00558 /*************************************************************************************************/
00559 
00560 #endif
00561 
00562 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google