Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diego-ivan/libvalentine
A multithreaded CSV serializer and deserializer for GLib.Objects
https://github.com/diego-ivan/libvalentine
csv vala vala-libraries vala-library
Last synced: 11 days ago
JSON representation
A multithreaded CSV serializer and deserializer for GLib.Objects
- Host: GitHub
- URL: https://github.com/diego-ivan/libvalentine
- Owner: Diego-Ivan
- License: lgpl-3.0
- Created: 2022-07-23T04:48:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T04:08:34.000Z (almost 2 years ago)
- Last Synced: 2024-10-25T09:26:51.253Z (about 2 months ago)
- Topics: csv, vala, vala-libraries, vala-library
- Language: Vala
- Homepage:
- Size: 88.9 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Libvalentine
A library that can convert a CSV file to GLib.Objects and viceversa. For example:
```vala
public class Example : Object {
public string name { get; set; default = "hello"; }
public int something { get; set; default = 1; }
// This property is private read, therefore it won't appear in the CSV file
public bool boolean { private get; set; default = false; }
}var serializer = new Valentine.ObjectSerializer ();
example.add_object (new Example ());
example.add_object (new Example () { name = "Hola" });
example.add_object (new Example () { something = 2 });
```Will have the following output:
```csv
name,something
"hello","1"
"hola","1"
"hello","2"
```Parsing a CSV text is done in the following way:
```vala
string csv = """name,something
"Object 1,"45"
"Object 7","19"
"Object 9","13"
"""var deserializer = new Valentine.ObjectDeserializer ();
List object_list = deserializer.deserialize_from_string (csv);foreach (var object in Example) {
print ("name: %s; something: "%i", object.name, object.something);
}/*
* Output:
* name: Object 1; something: 45
* name: Object 7; something: 19
* name: Object 9; something: 13
*/
```## Usage
Valentine provides a simple API that converts GLib.Objects into a CSV file.
```vala
var serializer = new Valentine.ObjectSerializer ();
serializer.add_object (new Adw.Flap ());
serializer.add_object (new Adw.Flap ());stdout.printf (serializer.to_string ());
```It also provides an option to save the document directly to a file:
```vala
serializer.save_to_file ("/var/home/user/Documents/my_file.csv");
```It also provides an API that converts CSV files to Object Lists
```vala
var deserializer = new Valentine.ObjectDeserializer ();
List list = deserializer.deserializer_from_file ("/path/to/csv/file.csv");
```## Features
Support for property types:
- [x] Integers
- [x] Booleans
- [x] Strings
- [x] Chars
- [x] UChars
- [x] Longs
- [X] DateTimes
- [x] Files
- [x] Uint
- [x] Floats
- [x] Doubles
- [X] Variants
- [x] Flags
- [x] Enums
- [x] Possibility to add user defined functions to parse other types (such as custom classes)Other features:
- [x] Save directly to a file
- [x] Parse CSV file and create an object with an expected type