stlab.adobe.com Adobe Systems Incorporated
adam.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2005-2008 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ADAM_HPP
10 #define ADOBE_ADAM_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <functional>
15 
16 #include <boost/utility.hpp>
17 #include <boost/function.hpp>
18 
19 #ifdef __MWERKS__
20  #pragma warn_unusedarg off
21  #pragma warn_unusedvar off
22 #endif
23 
24 #include <boost/signals.hpp>
25 
26 #ifdef __MWERKS__
27  #pragma warn_unusedarg reset
28  #pragma warn_unusedvar reset
29 #endif
30 
32 #include <adobe/array.hpp>
33 #include <adobe/dictionary_fwd.hpp>
34 #include <adobe/istream.hpp>
35 #include <adobe/move.hpp>
36 #include <adobe/name_fwd.hpp>
37 #include <adobe/vector.hpp>
39 
40 /*
41 
42  REVISIT (sparent) : It would be best to detangle the sheet from
43  the virtual machine. The way to do this is to allow for funciton
44  objects to be passed instead of line positions and expression
45  arrays. The function object could bind to the line_position_t and
46  the array.... This would allow for easier programatic driving -
47  however, one would have to construct condition objects which
48  tracked dependencies and the sheet would require a get() method to
49  retrieve the value of a cell.
50 
51 */
52 
53 /*************************************************************************************************/
54 
55 namespace adobe {
56 
65 /*************************************************************************************************/
66 
73 class sheet_t : boost::noncopyable
74 {
75  public:
76  struct relation_t;
77 
82 
96  typedef boost::signals::connection connection_t;
97 
98  #if !defined(ADOBE_NO_DOCUMENTATION)
99  sheet_t();
100  ~sheet_t();
101  #endif
102 
110  any_regular_t inspect(const array_t& expression);
111 
118  void set(name_t cell, const any_regular_t& value); // input cell.
119 
141  void touch(const name_t* first, const name_t* last); // range of input cells.
142 
151  any_regular_t get(name_t cell);
152 
164  void add_input (name_t name, const line_position_t& position, const array_t& initializer);
165 
178  void add_output (name_t name, const line_position_t& position, const array_t& expression);
179 
180 
194  void add_constant (name_t name, const line_position_t& position, const array_t& initializer);
195 
196 
206  void add_constant(name_t name, any_regular_t value);
207 
219  void add_logic (name_t name, const line_position_t& position, const array_t& expression);
220 
232  void add_invariant (name_t name, const line_position_t& position, const array_t& expression);
233 
254  void add_interface (name_t name, bool linked, const line_position_t& position1,
255  const array_t& initializer, const line_position_t& position2,
256  const array_t& expression);
257 
269  void add_interface(name_t name, any_regular_t initial);
270 
292  void add_relation(const line_position_t& position, const array_t& conditional,
293  const relation_t* first, const relation_t* last);
294 
295 
310  connection_t monitor_value(name_t name, const monitor_value_t& proc);
311 
333  connection_t monitor_contributing(name_t cell, const dictionary_t& mark,
334  const monitor_contributing_t& proc);
335  // output only
336 
389  connection_t monitor_enabled(name_t cell, const name_t* first, const name_t* last,
390  const monitor_enabled_t& proc); // input only
391 
392  #if 0
393  connection_t monitor_invariant_contributing(name_t input, const monitor_invariant_t&);
394  #endif
395 
412  connection_t monitor_invariant_dependent(name_t output, const monitor_invariant_t& proc);
413 
414 
425  bool has_input(name_t name) const;
426 
437  bool has_output(name_t name) const;
438 
449  std::size_t count_interface(name_t name) const
450  { return has_input(name) && has_output(name); }
451 
452 
460  void update();
461 
470  void reinitialize();
471 
472 
481  void set(const dictionary_t& dictionary);
482 
483  #if 0
484  dictionary_t current_mark() const;
485  #endif
486 
487 
495  dictionary_t contributing(const dictionary_t& mark) const;
496 
503  dictionary_t contributing() const;
504 
509 
510  /*
511  REVISIT (fbrereto) : From a note from sparent 2007/04/13:
512 
513  "Make the adam VM public - eventually I'm going to pull it out all
514  together (The property model library won't directly depend on it -
515  only function object - which can be implemented with the VM)."
516 
517  This solution is a bit hackish, but is a viable intermediary solution;
518  because sheet_t and its underlying implementation are noncopyable, the
519  machine can be stored here and held by reference by the implementation,
520  and everything is fine. Nevertheless, this is an interim solution given
521  Sean's plans for the VM's relationship to sheet_t in the future.
522  */
524 
525  private:
526  class implementation_t;
527  implementation_t* object_m;
528 };
529 
530 /*************************************************************************************************/
531 
538 struct set_monitor_t : std::unary_function<any_regular_t, void>
539 {
540  set_monitor_t(sheet_t& sheet, name_t cell_name) :
541  cell_name_m(cell_name),
542  sheet_m(sheet)
543  { }
544 
545  void operator()(const any_regular_t& x)
546  { sheet_m.get().set(cell_name_m, x); }
547 
548  private:
549  name_t cell_name_m;
550  boost::reference_wrapper<sheet_t> sheet_m;
551 };
552 
553 /*************************************************************************************************/
554 
555 /*
556  REVISIT (sparent) : line_position_t and array_t need to go in favor of a function object.
557 */
558 
565 {
568  name_set_m(n),
569  position_m(p),
570  expression_m(adobe::move(e))
571  { }
572 
573  friend void swap(relation_t& x, relation_t& y)
574  {
575  swap(x.name_set_m, y.name_set_m);
576  swap(x.position_m, y.position_m);
578  }
579 
581  name_set_m(x.source.name_set_m),
582  position_m(x.source.position_m),
583  expression_m(adobe::move(x.source.expression_m))
584  { }
585 
587  { swap(*this, x); return *this; }
588 
589 
593 };
594 
595 /*************************************************************************************************/
596 
597 } // namespace adobe
598 
599 /*************************************************************************************************/
600 
601 #endif
602 
603 /*************************************************************************************************/
The fundamental data structure for the Property Model engine.
Definition: adam.hpp:73
vector< name_t > name_set_m
Definition: adam.hpp:590
std::size_t count_interface(name_t name) const
Definition: adam.hpp:449
boost::function< void(const any_regular_t &)> monitor_value_t
Definition: adam.hpp:79
friend void swap(relation_t &x, relation_t &y)
Definition: adam.hpp:573
line_position_t position_m
Definition: adam.hpp:591
void add_relation(const line_position_t &position, const array_t &conditional, const relation_t *first, const relation_t *last)
boost::function< void(bool)> monitor_invariant_t
Definition: adam.hpp:76
A type detailing parser position information.
Definition: istream.hpp:153
Adam support class.
Definition: adam.hpp:538
move_from is used for move_ctors.
Definition: move.hpp:306
boost::function< void(bool)> monitor_enabled_t
Definition: adam.hpp:81
virtual_machine_t machine_m
Definition: adam.hpp:523
void reinitialize()
bool has_input(name_t name) const
set_monitor_t(sheet_t &sheet, name_t cell_name)
Definition: adam.hpp:540
dictionary_t contributing_to_cell(name_t) const
dictionary_t contributing() const
void add_constant(name_t name, const line_position_t &position, const array_t &initializer)
boost::signals::connection connection_t
Definition: adam.hpp:96
void add_interface(name_t name, bool linked, const line_position_t &position1, const array_t &initializer, const line_position_t &position2, const array_t &expression)
void operator()(const any_regular_t &x)
Definition: adam.hpp:545
relation_t(move_from< relation_t > x)
Definition: adam.hpp:580
void add_output(name_t name, const line_position_t &position, const array_t &expression)
void add_invariant(name_t name, const line_position_t &position, const array_t &expression)
void add_logic(name_t name, const line_position_t &position, const array_t &expression)
connection_t monitor_contributing(name_t cell, const dictionary_t &mark, const monitor_contributing_t &proc)
relation_t(vector< name_t > n, line_position_t p, array_t e)
Definition: adam.hpp:567
connection_t monitor_invariant_dependent(name_t output, const monitor_invariant_t &proc)
void set(name_t cell, const any_regular_t &value)
connection_t monitor_enabled(name_t cell, const name_t *first, const name_t *last, const monitor_enabled_t &proc)
connection_t monitor_value(name_t name, const monitor_value_t &proc)
any_regular_t inspect(const array_t &expression)
boost::function< void(const dictionary_t &)> monitor_contributing_t
Definition: adam.hpp:80
void add_input(name_t name, const line_position_t &position, const array_t &initializer)
void touch(const name_t *first, const name_t *last)
relation_t & operator=(relation_t x)
Definition: adam.hpp:586
A runtime polymorphic type similar to boost::any which can hold any type which models Regular...
Adam support class for related relationships.
Definition: adam.hpp:564
bool has_output(name_t name) const

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