Back to index

texmacs  1.0.7.15
tmfs_table.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tmfs_basis.cpp
00004 * DESCRIPTION: low-level disk functions for the TeXmacs file system
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 #include "file.hpp"
00014 
00015 /******************************************************************************
00016 * The TeXmacs file system and the two major operations
00017 ******************************************************************************/
00018 
00019 disk_table tmfs;
00020 
00021 void
00022 tmfs_initialize () {
00023   if (is_nil (tmfs)) tmfs= disk_table ("$TEXMACS_HOME_PATH/tmfs");
00024 }
00025 
00026 void
00027 tmfs_write (transaction t) {
00028   tmfs_initialize ();
00029   tmfs->write (t);
00030 }
00031 
00032 transaction
00033 tmfs_read (collection c) {
00034   tmfs_initialize ();
00035   return tmfs->read (c);
00036 }
00037 
00038 /******************************************************************************
00039 * Set, reset and get
00040 ******************************************************************************/
00041 
00042 void
00043 tmfs_set (string key, collection val) {
00044   tmfs_write (atom (key, val));
00045 }
00046 
00047 void
00048 tmfs_set (string key, string val) {
00049   tmfs_write (atom (key, singleton (val, 1)));
00050 }
00051 
00052 void
00053 tmfs_reset (string key, collection val) {
00054   tmfs_write (atom (key, invert (val)));
00055 }
00056 
00057 void
00058 tmfs_reset (string key, string val) {
00059   tmfs_write (atom (key, singleton (val, -1)));
00060 }
00061 
00062 collection
00063 tmfs_get (string key) {
00064   transaction t= tmfs_read (singleton (key));
00065   return simplify (t[key]);
00066 }
00067 
00068 /******************************************************************************
00069 * Saving, removing and loading plain files
00070 ******************************************************************************/
00071 
00072 void
00073 tmfs_save (string key, string val) {
00074   tmfs_write (atom (key, singleton (val, 3)));
00075 }
00076 
00077 void
00078 tmfs_remove (string key) {
00079   tmfs_write (atom (key, singleton ("*", -3)));
00080 }
00081 
00082 string
00083 tmfs_load (string key) {
00084   transaction t= tmfs_read (singleton (key, 3));
00085   collection  c= simplify (t[key]);
00086   if (N(c) != 1) return "";
00087   return first (c);
00088 }