[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:54:41 UTC 2010
The following commit has been merged in the master branch:
commit 7805d40b48c71f4e0a46055a20c1aed72d54652f
Author: John Goerzen <jgoerzen at complete.org>
Date: Wed Feb 2 05:18:39 2005 +0100
Added StringDBM
Keywords:
(jgoerzen at complete.org--projects/missingh--head--0.7--patch-185)
diff --git a/ChangeLog b/ChangeLog
index 5bd0130..ca2c676 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,26 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.7
#
+2005-02-01 22:18:39 GMT John Goerzen <jgoerzen at complete.org> patch-185
+
+ Summary:
+ Added StringDBM
+ Revision:
+ missingh--head--0.7--patch-185
+
+
+ new files:
+ libsrc/MissingH/AnyDBM/.arch-ids/=id
+ libsrc/MissingH/AnyDBM/FiniteMapDBM.hs
+ libsrc/MissingH/AnyDBM/StringDBM.hs
+
+ modified files:
+ ChangeLog MissingH.cabal libsrc/MissingH/AnyDBM.hs
+
+ new directories:
+ libsrc/MissingH/AnyDBM libsrc/MissingH/AnyDBM/.arch-ids
+
+
2005-02-01 21:30:41 GMT John Goerzen <jgoerzen at complete.org> patch-184
Summary:
diff --git a/MissingH.cabal b/MissingH.cabal
index 7cc24cf..90fd536 100644
--- a/MissingH.cabal
+++ b/MissingH.cabal
@@ -66,7 +66,9 @@ Exposed-Modules: MissingH.IO, MissingH.IO.Binary, MissingH.List,
MissingH.Wash.Utility.SimpleParser,
MissingH.Wash.Utility.URLCoding,
MissingH.Wash.Utility.Unique,
- MissingH.AnyDBM
+ MissingH.AnyDBM,
+ MissingH.AnyDBM.FiniteMapDBM,
+ MissingH.AnyDBM.StringDBM
HS-Source-Dir: libsrc
Extensions: ExistentialQuantification, AllowOverlappingInstances,
AllowUndecidableInstances
diff --git a/libsrc/MissingH/AnyDBM.hs b/libsrc/MissingH/AnyDBM.hs
index 31a5473..2cd5b76 100644
--- a/libsrc/MissingH/AnyDBM.hs
+++ b/libsrc/MissingH/AnyDBM.hs
@@ -55,6 +55,10 @@ class AnyDBM a where
{- | Close the object, writing out any unsaved data to disk if necessary.
If you implement this, make sure your implementation calls 'flushA'.
+
+ Note: if you have an object opened for writing, you MUST
+ call closeA on it when you are done. Implementations are not
+ required to preserve your data otherwise.
-}
closeA :: a -> IO ()
diff --git a/libsrc/MissingH/AnyDBM/FiniteMapDBM.hs b/libsrc/MissingH/AnyDBM/FiniteMapDBM.hs
new file mode 100644
index 0000000..294ed3f
--- /dev/null
+++ b/libsrc/MissingH/AnyDBM/FiniteMapDBM.hs
@@ -0,0 +1,68 @@
+{- arch-tag: Support for in-memory FiniteMaps as AnyDBM objects
+Copyright (C) 2005 John Goerzen <jgoerzen at complete.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+-}
+
+{- |
+ Module : MissingH.AnyDBM.FiniteMapDBM
+ Copyright : Copyright (C) 2005 John Goerzen
+ License : GNU GPL, version 2 or above
+
+ Maintainer : John Goerzen,
+ Maintainer : jgoerzen at complete.org
+ Stability : provisional
+ Portability: portable
+
+Written by John Goerzen, jgoerzen\@complete.org
+
+Support for working with FiniteMaps through the "MissingH.AnyDBM" framework.
+-}
+
+module MissingH.AnyDBM.FiniteMapDBM (FiniteMapDBM,
+ newFiniteMapDBM,
+ setFiniteMapDBM,
+ getFiniteMapDBM
+ )
+where
+import MissingH.AnyDBM
+import Data.FiniteMap
+import Data.IORef
+
+{- | The type of the FiniteMapDBM. -}
+type FiniteMapDBM = IORef (FiniteMap String String)
+
+{- | Makes a new FiniteMapDBM with an empty FiniteMap. -}
+newFiniteMapDBM :: IO FiniteMapDBM
+newFiniteMapDBM = newIORef emptyFM
+
+{- | Sets the embedded FiniteMap in this 'FiniteMapDBM' to the
+given 'FiniteMap'. -}
+setFiniteMapDBM :: FiniteMapDBM -> FiniteMap String String -> IO ()
+setFiniteMapDBM h fm = writeIORef h fm
+
+{- | Gets the embedded FiniteMap in this 'FiniteMapDBM'. -}
+getFiniteMapDBM :: FiniteMapDBM -> IO (FiniteMap String String)
+getFiniteMapDBM = readIORef
+
+m = modifyIORef
+
+instance AnyDBM FiniteMapDBM where
+ insertA h k v = m h (\x -> addToFM x k v)
+ deleteA h k = m h (\x -> delFromFM x k)
+ lookupA h k = do fm <- readIORef h
+ return $ lookupFM fm k
+ toListA h = do fm <- readIORef h
+ return $ fmToList fm
\ No newline at end of file
diff --git a/libsrc/MissingH/AnyDBM/StringDBM.hs b/libsrc/MissingH/AnyDBM/StringDBM.hs
new file mode 100644
index 0000000..8701702
--- /dev/null
+++ b/libsrc/MissingH/AnyDBM/StringDBM.hs
@@ -0,0 +1,79 @@
+{- arch-tag: Support for persistent storage through strings
+Copyright (C) 2005 John Goerzen <jgoerzen at complete.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+-}
+
+{- |
+ Module : MissingH.AnyDBM.StringDBM
+ Copyright : Copyright (C) 2005 John Goerzen
+ License : GNU GPL, version 2 or above
+
+ Maintainer : John Goerzen,
+ Maintainer : jgoerzen at complete.org
+ Stability : provisional
+ Portability: portable
+
+Written by John Goerzen, jgoerzen\@complete.org
+
+This 'MissingH.AnyDBM.AnyDBM' implementation is very simple. It can store
+data on-disk in a persistent fashion, using a very simple String
+representation. While the file is open, an in-memory cache is maintained.
+The data is written out during a call to 'flush' or 'close'.
+-}
+
+module MissingH.AnyDBM.StringDBM (StringDBM,
+ openStringDBM
+ )
+where
+import MissingH.AnyDBM
+import System.IO
+import Data.HashTable
+
+{- | The type of the StringDBM instances. -}
+data StringDBM = StringDBM (HashTable String String) IOMode FilePath
+
+{- | Opens a 'StringDBM' file. Please note: only ReadMode, WriteMode,
+and ReadWriteMode are supported for the IOMode. AppendMode is not supported.
+-}
+openStringDBM :: FilePath -> IOMode -> IO StringDBM
+openStringDBM _ AppendMode = fail "openStringDBM: AppendMode is not supported"
+openStringDBM fp ReadMode =
+ do ht <- new (==) hashString
+ readFile fp >>= strToA ht
+ return $ StringDBM ht ReadMode fp
+openStringDBM fp WriteMode =
+ do ht <- new (==) hashString
+ return $ StringDBM ht WriteMode fp
+openStringDBM fp ReadWriteMode =
+ -- Nothing different to start with. Later, we emulate WriteMode.
+ -- Nothing is ever read after the object is created.
+ do o <- openStringDBM fp ReadMode
+ case o of
+ StringDBM x _ y -> return $ StringDBM x WriteMode y
+
+g :: StringDBM -> HashTable String String
+g (StringDBM ht _ _) = ht
+
+instance AnyDBM StringDBM where
+ flushA (StringDBM ht WriteMode fp) =
+ do s <- strFromA ht
+ writeFile fp s
+ flushA _ = return ()
+
+ insertA = insertA . g
+ deleteA = deleteA . g
+ lookupA = lookupA . g
+ toListA = toListA . g
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list