Adobe Source Libraries 2.0.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
adam.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_ADAM_HPP
9#define ADOBE_ADAM_HPP
10
11#include <adobe/config.hpp>
12
13#include <functional>
14#include <vector>
15
16#include <boost/signals2/signal.hpp>
17
19#include <adobe/array.hpp>
21#include <adobe/istream.hpp>
22#include <adobe/name.hpp>
24
25/*
26
27 REVISIT (sparent) : It would be best to untangle the sheet from
28 the virtual machine. The way to do this is to allow for function
29 objects to be passed instead of line positions and expression
30 arrays. The function object could bind to the line_position_t and
31 the array.... This would allow for easier programmatic driving.
32
33*/
34
35/**************************************************************************************************/
36
37namespace adobe {
38
46
47/**************************************************************************************************/
48
55class sheet_t : boost::noncopyable {
56public:
57 struct relation_t;
58
59 using monitor_invariant_t = std::function<void(bool)>;
60 using monitor_value_t = std::function<void(const any_regular_t&)>;
61 using monitor_contributing_t = std::function<void(const dictionary_t&)>;
62 using monitor_enabled_t = std::function<void(bool)>;
63
76
77 typedef boost::signals2::connection connection_t;
78
79#if !defined(ADOBE_NO_DOCUMENTATION)
82#endif
83
91 any_regular_t inspect(const array_t& expression);
92
99 void set(name_t cell, const any_regular_t& value); // input cell.
100
122 void touch(const name_t* first, const name_t* last); // range of input cells.
123
131
132 // REVISIT (sparent) : get() is likely a bad name giving the pairing with set.
134
140 const any_regular_t& operator[](name_t cell) const;
141
153 void add_input(name_t name, const line_position_t& position, const array_t& initializer);
154
166
167 void add_output(name_t name, const line_position_t& position, const array_t& expression);
168
169
183 void add_constant(name_t name, const line_position_t& position, const array_t& initializer);
184
185
194
206 void add_logic(name_t name, const line_position_t& position, const array_t& expression);
207
219 void add_invariant(name_t name, const line_position_t& position, const array_t& expression);
220
241 void add_interface(name_t name, bool linked, const line_position_t& position1,
242 const array_t& initializer, const line_position_t& position2,
243 const array_t& expression);
244
256 void add_interface(name_t name, any_regular_t initial);
257
279 void add_relation(const line_position_t& position, const array_t& conditional,
280 const relation_t* first, const relation_t* last);
281
282
298
321 const monitor_contributing_t& proc);
322 // output only
323
376 connection_t monitor_enabled(name_t cell, const name_t* first, const name_t* last,
377 const monitor_enabled_t& proc); // input only
378
379#if 0
380 connection_t monitor_invariant_contributing(name_t input, const monitor_invariant_t&);
381#endif
382
400
401
412 bool has_input(name_t name) const;
413
424 bool has_output(name_t name) const;
425
435
436 std::size_t count_interface(name_t name) const { return has_input(name) && has_output(name); }
437
438
446 void update();
447
457
458
467 void set(const dictionary_t& dictionary);
468
469#if 0
470 dictionary_t current_mark() const;
471#endif
472
473
482
488
490
495
496 /*
497 REVISIT (fbrereto) : From a note from sparent 2007/04/13:
498
499 "Make the adam VM public - eventually I'm going to pull it out all
500 together (The property model library won't directly depend on it -
501 only function object - which can be implemented with the VM)."
502
503 This solution is a bit hackish, but is a viable intermediary solution;
504 because sheet_t and its underlying implementation are noncopyable, the
505 machine can be stored here and held by reference by the implementation,
506 and everything is fine. Nevertheless, this is an interim solution given
507 Sean's plans for the VM's relationship to sheet_t in the future.
508 */
510
511private:
512 class implementation_t;
513 implementation_t* object_m;
514};
515
516/**************************************************************************************************/
517
523
525 set_monitor_t(sheet_t& sheet, name_t cell_name) : cell_name_m(cell_name), sheet_m(sheet) {}
526
527 void operator()(const any_regular_t& x) { sheet_m.get().set(cell_name_m, x); }
528
529private:
530 name_t cell_name_m;
531 std::reference_wrapper<sheet_t> sheet_m;
532};
533
534/**************************************************************************************************/
535
536/*
537 REVISIT (sparent) : line_position_t and array_t need to go in favor of a function object.
538*/
539
547 relation_t(std::vector<name_t> n, line_position_t p, array_t e)
548 : name_set_m(std::begin(n), std::end(n)), position_m(p), expression_m(std::move(e)) {}
549
550 friend void swap(relation_t& x, relation_t& y) {
554 }
555
556 relation_t(relation_t&& x) noexcept
557 : name_set_m(x.name_set_m), position_m(x.position_m),
558 expression_m(std::move(x.expression_m)) {}
559
560 relation_t(const relation_t&) = default;
561
563 swap(*this, x);
564 return *this;
565 }
566
567
568 std::vector<name_t> name_set_m;
571};
572
573/**************************************************************************************************/
574
575} // namespace adobe
576
577/**************************************************************************************************/
578
579#endif
580
581/**************************************************************************************************/
The fundamental data structure for the Property Model engine.
Definition adam.hpp:55
void add_input(name_t name, const line_position_t &position, const array_t &initializer)
connection_t monitor_contributing(name_t cell, const dictionary_t &mark, const monitor_contributing_t &proc)
std::size_t count_interface(name_t name) const
Definition adam.hpp:436
bool has_input(name_t name) const
bool has_output(name_t name) const
any_regular_t inspect(const array_t &expression)
dictionary_t contributing_to_cell(name_t) const
void set(const dictionary_t &dictionary)
void add_invariant(name_t name, const line_position_t &position, const array_t &expression)
void add_interface(name_t name, any_regular_t initial)
connection_t monitor_value(name_t name, const monitor_value_t &proc)
void touch(const name_t *first, const name_t *last)
const any_regular_t & operator[](name_t cell) const
std::function< void(const any_regular_t &)> monitor_value_t
Definition adam.hpp:60
void add_relation(const line_position_t &position, const array_t &conditional, const relation_t *first, const relation_t *last)
void add_constant(name_t name, any_regular_t value)
void add_logic(name_t name, const line_position_t &position, const array_t &expression)
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)
dictionary_t contributing(const dictionary_t &mark) const
connection_t monitor_invariant_dependent(name_t output, const monitor_invariant_t &proc)
boost::signals2::connection connection_t
Definition adam.hpp:77
std::function< void(bool)> monitor_enabled_t
Definition adam.hpp:62
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)
std::function< void(const dictionary_t &)> monitor_contributing_t
Definition adam.hpp:61
void reinitialize()
dictionary_t contributing() const
void add_output(name_t name, const line_position_t &position, const array_t &expression)
any_regular_t get(name_t cell)
std::function< void(bool)> monitor_invariant_t
Definition adam.hpp:59
virtual_machine_t machine_m
Definition adam.hpp:509
void add_constant(name_t name, const line_position_t &position, const array_t &initializer)
A runtime polymorphic type similar to std::any which can hold any type which models Regular.
Stack-based non-branching expression evaluator.
closed_hash_map< name_t, any_regular_t > dictionary_t
std::vector< any_regular_t > array_t
Definition array_fwd.hpp:23
STL namespace.
A type detailing parser position information.
Definition istream.hpp:127
A character string class for immutable strings.
Definition name.hpp:220
void operator()(const any_regular_t &x)
Definition adam.hpp:527
set_monitor_t(sheet_t &sheet, name_t cell_name)
Definition adam.hpp:525
Adam support class for related relationships.
Definition adam.hpp:545
line_position_t position_m
Definition adam.hpp:569
relation_t & operator=(relation_t x)
Definition adam.hpp:562
friend void swap(relation_t &x, relation_t &y)
Definition adam.hpp:550
relation_t(relation_t &&x) noexcept
Definition adam.hpp:556
relation_t(const relation_t &)=default
std::vector< name_t > name_set_m
Definition adam.hpp:568
relation_t(std::vector< name_t > n, line_position_t p, array_t e)
Definition adam.hpp:547