Back to index

texmacs  1.0.7.15
transaction.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : transaction.cpp
00004 * DESCRIPTION: transactions or changesets
00005 * COPYRIGHT  : (C) 2007  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "tmfs.hpp"
00013 
00014 /******************************************************************************
00015 * Routines for transactions
00016 ******************************************************************************/
00017 
00018 transaction
00019 atom (string key, collection val) {
00020   transaction t;
00021   t(key)= val;
00022   return t;
00023 }
00024 
00025 void
00026 add (transaction& t, string key, string val, int eps) {
00027   //cout << "Add " << key << ", " << val << ", " << eps << "\n";
00028   if (!t->contains (key)) t (key)= collection ();
00029   t (key) (val)= eps;
00030 }
00031 
00032 transaction
00033 filter (transaction t, bool file_flag) {
00034   transaction r;
00035   iterator<string> it= iterate (t);
00036   while (it->busy ()) {
00037     string s= it->next ();
00038     collection c= filter (t[s], file_flag);
00039     if (N(c) != 0) r(s)= c;
00040   }
00041   return r;
00042 }
00043 
00044 transaction
00045 simplify (transaction t) {
00046   transaction r;
00047   iterator<string> it= iterate (t);
00048   while (it->busy ()) {
00049     string s= it->next ();
00050     collection c= simplify (t[s]);
00051     if (N(c) != 0) r(s)= c;
00052   }
00053   return r;
00054 }
00055 
00056 transaction
00057 invert (transaction t) {
00058   transaction r;
00059   iterator<string> it= iterate (t);
00060   while (it->busy ()) {
00061     string s= it->next ();
00062     r(s)= invert (t[s]);
00063   }
00064   return r;
00065 }
00066 
00067 void
00068 merge (transaction& t1, transaction t2) {
00069   //cout << "Merge " << t1 << ", " << t2 << "\n";
00070   iterator<string> it= iterate (t2);
00071   while (it->busy()) {
00072     string s= it->next ();
00073     if (!t1->contains (s)) t1(s)= collection ();
00074     merge (t1(s), t2[s]);
00075   }
00076 }
00077 
00078 transaction
00079 operator * (transaction t1, transaction t2) {
00080   transaction r;
00081   merge (r, t1);
00082   merge (r, t2);
00083   return r;
00084 }
00085 
00086 int
00087 total_size (transaction t) {
00088   int sz= 1;
00089   iterator<string> it= iterate (t);
00090   while (it->busy ()) {
00091     string s= it->next ();
00092     sz += N(s) + total_size (t[s]);
00093   }
00094   return sz;
00095 }