app :: data_store
Serializable::inspect to show more useful information
			serialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Key/value storage services
#
# The main services is `App::data_store`, a `DataStore` holding any
# serializable Nit object.
module data_store
import app_base
import serialization
# Platform variations
import linux::data_store is conditional(linux)
import android::data_store is conditional(android)
import ios::data_store is conditional(ios)
redef class App
	# Services to store and load data
	#
	# ~~~
	# import app::ui
	# import app::data_store
	#
	# class MyWindow
	#     super Window
	#
	#     var state = "Simple string or any serializable class"
	#
	#     redef fun on_save_state do app.data_store["state"] = state
	#
	#     redef fun on_restore_state
	#     do
	#         var state = app.data_store["state"]
	#         if state isa String then self.state = state
	#     end
	# end
	# ~~~
	var data_store = new DataStore is lazy
end
# Simple data storage facility
#
# Write values with `[]=` and read with `[]`.
# ~~~
# import linux::data_store # Needed for testing only
#
# class A
#     serialize
#
#     var b = true
#     var f = 1.234
# end
#
# var data_store = new DataStore
# data_store["one"] = 1
# data_store["str"] = "Some string"
# data_store["a"] = new A
#
# assert data_store["one"] == 1
# assert data_store["str"] == "Some string"
# assert data_store["a"].as(A).b
# assert data_store["a"].as(A).f == 1.234
# assert data_store["other"] == null
# ~~~
#
# Set to `null` to clear a value.
# ~~~
# data_store["one"] = null
# assert data_store["one"] == null
# ~~~
class DataStore
	# Get the object stored at `key`, or null if nothing is available
	fun [](key: String): nullable Object is abstract
	# Store `value` at `key`
	fun []=(key: String, value: nullable Serializable) is abstract
end
lib/app/data_store.nit:17,1--93,3