{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE AllowAmbiguousTypes #-}

{-# OPTIONS_HADDOCK not-home #-}

module FlatBuffers.Internal.Types where

import           Data.Word
import           FlatBuffers.Internal.Compiler.Display ( Display )

-- | Metadata for a struct type.
class IsStruct a where
  structAlignmentOf :: Alignment
  structSizeOf      :: InlineSize

-- | The number of bytes occupied by a piece of data that's stored "inline"
--
-- "inline" here means "stored directly in a table or a vector, and not by reference".
-- E.g.: numeric types, booleans, structs, offsets.
newtype InlineSize = InlineSize { InlineSize -> Word16
unInlineSize :: Word16 }
  deriving newtype (Int -> InlineSize -> ShowS
[InlineSize] -> ShowS
InlineSize -> String
(Int -> InlineSize -> ShowS)
-> (InlineSize -> String)
-> ([InlineSize] -> ShowS)
-> Show InlineSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InlineSize] -> ShowS
$cshowList :: [InlineSize] -> ShowS
show :: InlineSize -> String
$cshow :: InlineSize -> String
showsPrec :: Int -> InlineSize -> ShowS
$cshowsPrec :: Int -> InlineSize -> ShowS
Show, InlineSize -> InlineSize -> Bool
(InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool) -> Eq InlineSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InlineSize -> InlineSize -> Bool
$c/= :: InlineSize -> InlineSize -> Bool
== :: InlineSize -> InlineSize -> Bool
$c== :: InlineSize -> InlineSize -> Bool
Eq, Integer -> InlineSize
InlineSize -> InlineSize
InlineSize -> InlineSize -> InlineSize
(InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (Integer -> InlineSize)
-> Num InlineSize
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> InlineSize
$cfromInteger :: Integer -> InlineSize
signum :: InlineSize -> InlineSize
$csignum :: InlineSize -> InlineSize
abs :: InlineSize -> InlineSize
$cabs :: InlineSize -> InlineSize
negate :: InlineSize -> InlineSize
$cnegate :: InlineSize -> InlineSize
* :: InlineSize -> InlineSize -> InlineSize
$c* :: InlineSize -> InlineSize -> InlineSize
- :: InlineSize -> InlineSize -> InlineSize
$c- :: InlineSize -> InlineSize -> InlineSize
+ :: InlineSize -> InlineSize -> InlineSize
$c+ :: InlineSize -> InlineSize -> InlineSize
Num, Int -> InlineSize
InlineSize -> Int
InlineSize -> [InlineSize]
InlineSize -> InlineSize
InlineSize -> InlineSize -> [InlineSize]
InlineSize -> InlineSize -> InlineSize -> [InlineSize]
(InlineSize -> InlineSize)
-> (InlineSize -> InlineSize)
-> (Int -> InlineSize)
-> (InlineSize -> Int)
-> (InlineSize -> [InlineSize])
-> (InlineSize -> InlineSize -> [InlineSize])
-> (InlineSize -> InlineSize -> [InlineSize])
-> (InlineSize -> InlineSize -> InlineSize -> [InlineSize])
-> Enum InlineSize
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: InlineSize -> InlineSize -> InlineSize -> [InlineSize]
$cenumFromThenTo :: InlineSize -> InlineSize -> InlineSize -> [InlineSize]
enumFromTo :: InlineSize -> InlineSize -> [InlineSize]
$cenumFromTo :: InlineSize -> InlineSize -> [InlineSize]
enumFromThen :: InlineSize -> InlineSize -> [InlineSize]
$cenumFromThen :: InlineSize -> InlineSize -> [InlineSize]
enumFrom :: InlineSize -> [InlineSize]
$cenumFrom :: InlineSize -> [InlineSize]
fromEnum :: InlineSize -> Int
$cfromEnum :: InlineSize -> Int
toEnum :: Int -> InlineSize
$ctoEnum :: Int -> InlineSize
pred :: InlineSize -> InlineSize
$cpred :: InlineSize -> InlineSize
succ :: InlineSize -> InlineSize
$csucc :: InlineSize -> InlineSize
Enum, Eq InlineSize
Eq InlineSize
-> (InlineSize -> InlineSize -> Ordering)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> Bool)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> Ord InlineSize
InlineSize -> InlineSize -> Bool
InlineSize -> InlineSize -> Ordering
InlineSize -> InlineSize -> InlineSize
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: InlineSize -> InlineSize -> InlineSize
$cmin :: InlineSize -> InlineSize -> InlineSize
max :: InlineSize -> InlineSize -> InlineSize
$cmax :: InlineSize -> InlineSize -> InlineSize
>= :: InlineSize -> InlineSize -> Bool
$c>= :: InlineSize -> InlineSize -> Bool
> :: InlineSize -> InlineSize -> Bool
$c> :: InlineSize -> InlineSize -> Bool
<= :: InlineSize -> InlineSize -> Bool
$c<= :: InlineSize -> InlineSize -> Bool
< :: InlineSize -> InlineSize -> Bool
$c< :: InlineSize -> InlineSize -> Bool
compare :: InlineSize -> InlineSize -> Ordering
$ccompare :: InlineSize -> InlineSize -> Ordering
$cp1Ord :: Eq InlineSize
Ord, Num InlineSize
Ord InlineSize
Num InlineSize
-> Ord InlineSize -> (InlineSize -> Rational) -> Real InlineSize
InlineSize -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: InlineSize -> Rational
$ctoRational :: InlineSize -> Rational
$cp2Real :: Ord InlineSize
$cp1Real :: Num InlineSize
Real, Enum InlineSize
Real InlineSize
Real InlineSize
-> Enum InlineSize
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> InlineSize)
-> (InlineSize -> InlineSize -> (InlineSize, InlineSize))
-> (InlineSize -> InlineSize -> (InlineSize, InlineSize))
-> (InlineSize -> Integer)
-> Integral InlineSize
InlineSize -> Integer
InlineSize -> InlineSize -> (InlineSize, InlineSize)
InlineSize -> InlineSize -> InlineSize
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: InlineSize -> Integer
$ctoInteger :: InlineSize -> Integer
divMod :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
$cdivMod :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
quotRem :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
$cquotRem :: InlineSize -> InlineSize -> (InlineSize, InlineSize)
mod :: InlineSize -> InlineSize -> InlineSize
$cmod :: InlineSize -> InlineSize -> InlineSize
div :: InlineSize -> InlineSize -> InlineSize
$cdiv :: InlineSize -> InlineSize -> InlineSize
rem :: InlineSize -> InlineSize -> InlineSize
$crem :: InlineSize -> InlineSize -> InlineSize
quot :: InlineSize -> InlineSize -> InlineSize
$cquot :: InlineSize -> InlineSize -> InlineSize
$cp2Integral :: Enum InlineSize
$cp1Integral :: Real InlineSize
Integral, InlineSize
InlineSize -> InlineSize -> Bounded InlineSize
forall a. a -> a -> Bounded a
maxBound :: InlineSize
$cmaxBound :: InlineSize
minBound :: InlineSize
$cminBound :: InlineSize
Bounded)

-- | The memory alignment (in bytes) for a piece of data in a flatbuffer.
-- E.g., `Data.Int.Int32` are always aligned to 4 bytes.
-- This number should always be a power of 2 in the range [1, 16].
newtype Alignment = Alignment { Alignment -> Word8
unAlignment :: Word8 }
  deriving newtype (Int -> Alignment -> ShowS
[Alignment] -> ShowS
Alignment -> String
(Int -> Alignment -> ShowS)
-> (Alignment -> String)
-> ([Alignment] -> ShowS)
-> Show Alignment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Alignment] -> ShowS
$cshowList :: [Alignment] -> ShowS
show :: Alignment -> String
$cshow :: Alignment -> String
showsPrec :: Int -> Alignment -> ShowS
$cshowsPrec :: Int -> Alignment -> ShowS
Show, Alignment -> Alignment -> Bool
(Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool) -> Eq Alignment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Alignment -> Alignment -> Bool
$c/= :: Alignment -> Alignment -> Bool
== :: Alignment -> Alignment -> Bool
$c== :: Alignment -> Alignment -> Bool
Eq, Integer -> Alignment
Alignment -> Alignment
Alignment -> Alignment -> Alignment
(Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Integer -> Alignment)
-> Num Alignment
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> Alignment
$cfromInteger :: Integer -> Alignment
signum :: Alignment -> Alignment
$csignum :: Alignment -> Alignment
abs :: Alignment -> Alignment
$cabs :: Alignment -> Alignment
negate :: Alignment -> Alignment
$cnegate :: Alignment -> Alignment
* :: Alignment -> Alignment -> Alignment
$c* :: Alignment -> Alignment -> Alignment
- :: Alignment -> Alignment -> Alignment
$c- :: Alignment -> Alignment -> Alignment
+ :: Alignment -> Alignment -> Alignment
$c+ :: Alignment -> Alignment -> Alignment
Num, Int -> Alignment
Alignment -> Int
Alignment -> [Alignment]
Alignment -> Alignment
Alignment -> Alignment -> [Alignment]
Alignment -> Alignment -> Alignment -> [Alignment]
(Alignment -> Alignment)
-> (Alignment -> Alignment)
-> (Int -> Alignment)
-> (Alignment -> Int)
-> (Alignment -> [Alignment])
-> (Alignment -> Alignment -> [Alignment])
-> (Alignment -> Alignment -> [Alignment])
-> (Alignment -> Alignment -> Alignment -> [Alignment])
-> Enum Alignment
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment]
$cenumFromThenTo :: Alignment -> Alignment -> Alignment -> [Alignment]
enumFromTo :: Alignment -> Alignment -> [Alignment]
$cenumFromTo :: Alignment -> Alignment -> [Alignment]
enumFromThen :: Alignment -> Alignment -> [Alignment]
$cenumFromThen :: Alignment -> Alignment -> [Alignment]
enumFrom :: Alignment -> [Alignment]
$cenumFrom :: Alignment -> [Alignment]
fromEnum :: Alignment -> Int
$cfromEnum :: Alignment -> Int
toEnum :: Int -> Alignment
$ctoEnum :: Int -> Alignment
pred :: Alignment -> Alignment
$cpred :: Alignment -> Alignment
succ :: Alignment -> Alignment
$csucc :: Alignment -> Alignment
Enum, Eq Alignment
Eq Alignment
-> (Alignment -> Alignment -> Ordering)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Bool)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> Ord Alignment
Alignment -> Alignment -> Bool
Alignment -> Alignment -> Ordering
Alignment -> Alignment -> Alignment
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Alignment -> Alignment -> Alignment
$cmin :: Alignment -> Alignment -> Alignment
max :: Alignment -> Alignment -> Alignment
$cmax :: Alignment -> Alignment -> Alignment
>= :: Alignment -> Alignment -> Bool
$c>= :: Alignment -> Alignment -> Bool
> :: Alignment -> Alignment -> Bool
$c> :: Alignment -> Alignment -> Bool
<= :: Alignment -> Alignment -> Bool
$c<= :: Alignment -> Alignment -> Bool
< :: Alignment -> Alignment -> Bool
$c< :: Alignment -> Alignment -> Bool
compare :: Alignment -> Alignment -> Ordering
$ccompare :: Alignment -> Alignment -> Ordering
$cp1Ord :: Eq Alignment
Ord, Num Alignment
Ord Alignment
Num Alignment
-> Ord Alignment -> (Alignment -> Rational) -> Real Alignment
Alignment -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
toRational :: Alignment -> Rational
$ctoRational :: Alignment -> Rational
$cp2Real :: Ord Alignment
$cp1Real :: Num Alignment
Real, Enum Alignment
Real Alignment
Real Alignment
-> Enum Alignment
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> Alignment)
-> (Alignment -> Alignment -> (Alignment, Alignment))
-> (Alignment -> Alignment -> (Alignment, Alignment))
-> (Alignment -> Integer)
-> Integral Alignment
Alignment -> Integer
Alignment -> Alignment -> (Alignment, Alignment)
Alignment -> Alignment -> Alignment
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: Alignment -> Integer
$ctoInteger :: Alignment -> Integer
divMod :: Alignment -> Alignment -> (Alignment, Alignment)
$cdivMod :: Alignment -> Alignment -> (Alignment, Alignment)
quotRem :: Alignment -> Alignment -> (Alignment, Alignment)
$cquotRem :: Alignment -> Alignment -> (Alignment, Alignment)
mod :: Alignment -> Alignment -> Alignment
$cmod :: Alignment -> Alignment -> Alignment
div :: Alignment -> Alignment -> Alignment
$cdiv :: Alignment -> Alignment -> Alignment
rem :: Alignment -> Alignment -> Alignment
$crem :: Alignment -> Alignment -> Alignment
quot :: Alignment -> Alignment -> Alignment
$cquot :: Alignment -> Alignment -> Alignment
$cp2Integral :: Enum Alignment
$cp1Integral :: Real Alignment
Integral, Alignment
Alignment -> Alignment -> Bounded Alignment
forall a. a -> a -> Bounded a
maxBound :: Alignment
$cmaxBound :: Alignment
minBound :: Alignment
$cminBound :: Alignment
Bounded, Alignment -> String
(Alignment -> String) -> Display Alignment
forall a. (a -> String) -> Display a
display :: Alignment -> String
$cdisplay :: Alignment -> String
Display)