Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
JsonGenerator
provides an object for generating a JSON data stream
from a tree of [structjson
.Node] instances, and put it into a buffer
or a file.
Synopsis
- newtype Generator = Generator (ManagedPtr Generator)
- class (GObject o, IsDescendantOf Generator o) => IsGenerator o
- toGenerator :: (MonadIO m, IsGenerator o) => o -> m Generator
- generatorGetIndent :: (HasCallStack, MonadIO m, IsGenerator a) => a -> m Word32
- generatorGetIndentChar :: (HasCallStack, MonadIO m, IsGenerator a) => a -> m Char
- generatorGetPretty :: (HasCallStack, MonadIO m, IsGenerator a) => a -> m Bool
- generatorGetRoot :: (HasCallStack, MonadIO m, IsGenerator a) => a -> m (Maybe Node)
- generatorNew :: (HasCallStack, MonadIO m) => m Generator
- generatorSetIndent :: (HasCallStack, MonadIO m, IsGenerator a) => a -> Word32 -> m ()
- generatorSetIndentChar :: (HasCallStack, MonadIO m, IsGenerator a) => a -> Char -> m ()
- generatorSetPretty :: (HasCallStack, MonadIO m, IsGenerator a) => a -> Bool -> m ()
- generatorSetRoot :: (HasCallStack, MonadIO m, IsGenerator a) => a -> Node -> m ()
- generatorToData :: (HasCallStack, MonadIO m, IsGenerator a) => a -> m (Text, Word64)
- generatorToFile :: (HasCallStack, MonadIO m, IsGenerator a) => a -> [Char] -> m ()
- generatorToGstring :: (HasCallStack, MonadIO m, IsGenerator a) => a -> String -> m String
- generatorToStream :: (HasCallStack, MonadIO m, IsGenerator a, IsOutputStream b, IsCancellable c) => a -> b -> Maybe c -> m ()
- constructGeneratorIndent :: (IsGenerator o, MonadIO m) => Word32 -> m (GValueConstruct o)
- getGeneratorIndent :: (MonadIO m, IsGenerator o) => o -> m Word32
- setGeneratorIndent :: (MonadIO m, IsGenerator o) => o -> Word32 -> m ()
- constructGeneratorIndentChar :: (IsGenerator o, MonadIO m) => Word32 -> m (GValueConstruct o)
- getGeneratorIndentChar :: (MonadIO m, IsGenerator o) => o -> m Word32
- setGeneratorIndentChar :: (MonadIO m, IsGenerator o) => o -> Word32 -> m ()
- constructGeneratorPretty :: (IsGenerator o, MonadIO m) => Bool -> m (GValueConstruct o)
- getGeneratorPretty :: (MonadIO m, IsGenerator o) => o -> m Bool
- setGeneratorPretty :: (MonadIO m, IsGenerator o) => o -> Bool -> m ()
- constructGeneratorRoot :: (IsGenerator o, MonadIO m) => Node -> m (GValueConstruct o)
- getGeneratorRoot :: (MonadIO m, IsGenerator o) => o -> m (Maybe Node)
- setGeneratorRoot :: (MonadIO m, IsGenerator o) => o -> Node -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq Generator Source # | |
GObject Generator Source # | |
Defined in GI.Json.Objects.Generator | |
ManagedPtrNewtype Generator Source # | |
Defined in GI.Json.Objects.Generator toManagedPtr :: Generator -> ManagedPtr Generator | |
TypedObject Generator Source # | |
Defined in GI.Json.Objects.Generator | |
HasParentTypes Generator Source # | |
Defined in GI.Json.Objects.Generator | |
IsGValue (Maybe Generator) Source # | Convert |
Defined in GI.Json.Objects.Generator gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe Generator -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe Generator) | |
type ParentTypes Generator Source # | |
Defined in GI.Json.Objects.Generator type ParentTypes Generator = '[Object] |
class (GObject o, IsDescendantOf Generator o) => IsGenerator o Source #
Type class for types which can be safely cast to Generator
, for instance with toGenerator
.
Instances
(GObject o, IsDescendantOf Generator o) => IsGenerator o Source # | |
Defined in GI.Json.Objects.Generator |
toGenerator :: (MonadIO m, IsGenerator o) => o -> m Generator Source #
Methods
Click to display all available methods, including inherited ones
Methods
bindProperty, bindPropertyFull, forceFloating, freezeNotify, getv, isFloating, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, toData, toFile, toGstring, toStream, unref, watchClosure.
Getters
getData, getIndent, getIndentChar, getPretty, getProperty, getQdata, getRoot.
Setters
setData, setDataFull, setIndent, setIndentChar, setPretty, setProperty, setRoot.
getIndent
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> m Word32 | Returns: the number of repetitions per indentation level |
Retrieves the value set using generatorSetIndent
.
Since: 0.14
getIndentChar
generatorGetIndentChar Source #
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> m Char | Returns: the character to be used when indenting |
Retrieves the value set using generatorSetIndentChar
.
Since: 0.14
getPretty
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> m Bool | Returns: |
Retrieves the value set using generatorSetPretty
.
Since: 0.14
getRoot
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> m (Maybe Node) | Returns: the root node |
Retrieves a pointer to the root node set using
generatorSetRoot
.
Since: 0.14
new
:: (HasCallStack, MonadIO m) | |
=> m Generator | Returns: the newly created generator instance |
Creates a new JsonGenerator
.
You can use this object to generate a JSON data stream starting from a
data object model composed by [structjson
.Node]s.
setIndent
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> Word32 |
|
-> m () |
Sets the number of repetitions for each indentation level.
Since: 0.14
setIndentChar
generatorSetIndentChar Source #
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> Char |
|
-> m () |
Sets the character to be used when indenting.
Since: 0.14
setPretty
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> Bool |
|
-> m () |
Sets whether the generated JSON should be pretty printed.
Pretty printing will use indentation character specified in the Generator:indentChar property and the spacing specified in the Generator:indent property.
Since: 0.14
setRoot
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> Node |
|
-> m () |
Sets the root of the JSON data stream to be serialized by the given generator.
The passed node
is copied by the generator object, so it can be
safely freed after calling this function.
toData
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> m (Text, Word64) | Returns: a newly allocated string holding a JSON data stream |
Generates a JSON data stream from generator
and returns it as a
buffer.
toFile
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> [Char] |
|
-> m () | (Can throw |
Creates a JSON data stream and puts it inside filename
, overwriting
the file's current contents.
This operation is atomic, in the sense that the data is written to a
temporary file which is then renamed to the given filename
.
toGstring
:: (HasCallStack, MonadIO m, IsGenerator a) | |
=> a |
|
-> String |
|
-> m String | Returns: the passed string, updated with the generated JSON data |
Generates a JSON data stream and appends it to the string buffer.
Since: 1.4
toStream
:: (HasCallStack, MonadIO m, IsGenerator a, IsOutputStream b, IsCancellable c) | |
=> a |
|
-> b |
|
-> Maybe c |
|
-> m () | (Can throw |
Outputs JSON data and writes it (synchronously) to the given stream.
Since: 0.12
Properties
indent
Number of spaces to be used to indent when pretty printing.
constructGeneratorIndent :: (IsGenerator o, MonadIO m) => Word32 -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “indent
” property. This is rarely needed directly, but it is used by new
.
getGeneratorIndent :: (MonadIO m, IsGenerator o) => o -> m Word32 Source #
Get the value of the “indent
” property.
When overloading is enabled, this is equivalent to
get
generator #indent
setGeneratorIndent :: (MonadIO m, IsGenerator o) => o -> Word32 -> m () Source #
Set the value of the “indent
” property.
When overloading is enabled, this is equivalent to
set
generator [ #indent:=
value ]
indentChar
The character that should be used when indenting in pretty print.
Since: 0.6
constructGeneratorIndentChar :: (IsGenerator o, MonadIO m) => Word32 -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “indent-char
” property. This is rarely needed directly, but it is used by new
.
getGeneratorIndentChar :: (MonadIO m, IsGenerator o) => o -> m Word32 Source #
Get the value of the “indent-char
” property.
When overloading is enabled, this is equivalent to
get
generator #indentChar
setGeneratorIndentChar :: (MonadIO m, IsGenerator o) => o -> Word32 -> m () Source #
Set the value of the “indent-char
” property.
When overloading is enabled, this is equivalent to
set
generator [ #indentChar:=
value ]
pretty
Whether the output should be "pretty-printed", with indentation and newlines.
The indentation level can be controlled by using the Generator:indent property.
constructGeneratorPretty :: (IsGenerator o, MonadIO m) => Bool -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “pretty
” property. This is rarely needed directly, but it is used by new
.
getGeneratorPretty :: (MonadIO m, IsGenerator o) => o -> m Bool Source #
Get the value of the “pretty
” property.
When overloading is enabled, this is equivalent to
get
generator #pretty
setGeneratorPretty :: (MonadIO m, IsGenerator o) => o -> Bool -> m () Source #
Set the value of the “pretty
” property.
When overloading is enabled, this is equivalent to
set
generator [ #pretty:=
value ]
root
The root node to be used when constructing a JSON data stream.
Since: 0.4
constructGeneratorRoot :: (IsGenerator o, MonadIO m) => Node -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “root
” property. This is rarely needed directly, but it is used by new
.
getGeneratorRoot :: (MonadIO m, IsGenerator o) => o -> m (Maybe Node) Source #
Get the value of the “root
” property.
When overloading is enabled, this is equivalent to
get
generator #root
setGeneratorRoot :: (MonadIO m, IsGenerator o) => o -> Node -> m () Source #
Set the value of the “root
” property.
When overloading is enabled, this is equivalent to
set
generator [ #root:=
value ]