Revision c4d68e39
b/Makefile.am | ||
---|---|---|
644 | 644 |
src/Ganeti/OpParams.hs \ |
645 | 645 |
src/Ganeti/Path.hs \ |
646 | 646 |
src/Ganeti/Parsers.hs \ |
647 |
src/Ganeti/PyValueInstances.hs \ |
|
647 | 648 |
src/Ganeti/Query/Cluster.hs \ |
648 | 649 |
src/Ganeti/Query/Common.hs \ |
649 | 650 |
src/Ganeti/Query/Export.hs \ |
b/src/Ganeti/OpCodes.hs | ||
---|---|---|
52 | 52 |
|
53 | 53 |
import qualified Ganeti.Hs2Py.OpDoc as OpDoc |
54 | 54 |
import Ganeti.OpParams |
55 |
import Ganeti.PyValueInstances () |
|
55 | 56 |
import Ganeti.Types |
56 | 57 |
import Ganeti.Query.Language (queryTypeOpToRaw) |
57 | 58 |
|
58 | 59 |
import Data.List (intercalate) |
59 | 60 |
import Data.Map (Map) |
60 |
import qualified Data.Map as Map |
|
61 |
import Data.Set (Set) |
|
62 |
import qualified Data.Set as Set |
|
63 | 61 |
|
64 | 62 |
import qualified Ganeti.Constants as C |
65 | 63 |
|
66 |
instance PyValue Bool |
|
67 |
instance PyValue Int |
|
68 |
instance PyValue Double |
|
69 |
instance PyValue Char |
|
70 |
|
|
71 |
instance (PyValue a, PyValue b) => PyValue (a, b) where |
|
72 |
showValue (x, y) = show (showValue x, showValue y) |
|
73 |
|
|
74 |
instance PyValue a => PyValue [a] where |
|
75 |
showValue xs = show (map showValue xs) |
|
76 |
|
|
77 |
instance PyValue a => PyValue (Set a) where |
|
78 |
showValue s = showValue (Set.toList s) |
|
79 |
|
|
80 |
instance (PyValue k, PyValue a) => PyValue (Map k a) where |
|
81 |
showValue mp = |
|
82 |
"{" ++ intercalate ", " (map showPair (Map.assocs mp)) ++ "}" |
|
83 |
where showPair (k, x) = show k ++ ":" ++ show x |
|
84 |
|
|
85 | 64 |
instance PyValue DiskIndex where |
86 | 65 |
showValue = showValue . unDiskIndex |
87 | 66 |
|
b/src/Ganeti/PyValueInstances.hs | ||
---|---|---|
1 |
{-| PyValueInstances contains instances for the 'PyValue' typeclass. |
|
2 |
|
|
3 |
The typeclass 'PyValue' converts Haskell values to Python values. |
|
4 |
This module contains instances of this typeclass for several generic |
|
5 |
types. These instances are used in the Haskell to Python generation |
|
6 |
of opcodes and constants, for example. |
|
7 |
|
|
8 |
-} |
|
9 |
|
|
10 |
{- |
|
11 |
|
|
12 |
Copyright (C) 2013 Google Inc. |
|
13 |
|
|
14 |
This program is free software; you can redistribute it and/or modify |
|
15 |
it under the terms of the GNU General Public License as published by |
|
16 |
the Free Software Foundation; either version 2 of the License, or |
|
17 |
(at your option) any later version. |
|
18 |
|
|
19 |
This program is distributed in the hope that it will be useful, but |
|
20 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
22 |
General Public License for more details. |
|
23 |
|
|
24 |
You should have received a copy of the GNU General Public License |
|
25 |
along with this program; if not, write to the Free Software |
|
26 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
27 |
02110-1301, USA. |
|
28 |
|
|
29 |
-} |
|
30 |
{-# LANGUAGE FlexibleInstances, OverlappingInstances, |
|
31 |
TypeSynonymInstances, IncoherentInstances #-} |
|
32 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
|
33 |
module Ganeti.PyValueInstances where |
|
34 |
|
|
35 |
import Data.List (intercalate) |
|
36 |
import Data.Map (Map) |
|
37 |
import qualified Data.Map as Map |
|
38 |
import Data.Set (Set) |
|
39 |
import qualified Data.Set as Set |
|
40 |
|
|
41 |
import Ganeti.THH |
|
42 |
|
|
43 |
instance PyValue Bool |
|
44 |
instance PyValue Int |
|
45 |
instance PyValue Double |
|
46 |
instance PyValue Char |
|
47 |
|
|
48 |
instance (PyValue a, PyValue b) => PyValue (a, b) where |
|
49 |
showValue (x, y) = show (showValue x, showValue y) |
|
50 |
|
|
51 |
instance PyValue String where |
|
52 |
showValue = show |
|
53 |
|
|
54 |
instance PyValue a => PyValue [a] where |
|
55 |
showValue xs = show (map showValue xs) |
|
56 |
|
|
57 |
instance (PyValue k, PyValue a) => PyValue (Map k a) where |
|
58 |
showValue mp = |
|
59 |
"{" ++ intercalate ", " (map showPair (Map.assocs mp)) ++ "}" |
|
60 |
where showPair (k, x) = show k ++ ":" ++ show x |
|
61 |
|
|
62 |
instance PyValue a => PyValue (Set a) where |
|
63 |
showValue s = showValue (Set.toList s) |
Also available in: Unified diff