Code Monkey home page Code Monkey logo

libvalentine's Introduction

Libvalentine

A library that can convert a CSV file to GLib.Objects and viceversa. For example:

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> ();
example.add_object (new Example ());
example.add_object (new Example () { name = "Hola" });
example.add_object (new Example () { something = 2 });

Will have the following output:

name,something
"hello","1"
"hola","1"
"hello","2"

Parsing a CSV text is done in the following way:

string csv = """name,something
"Object 1,"45"
"Object 7","19"
"Object 9","13"
"""

var deserializer = new Valentine.ObjectDeserializer<Example> ();
List<Example> 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.

var serializer = new Valentine.ObjectSerializer<Adw.Flap> ();
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:

serializer.save_to_file ("/var/home/user/Documents/my_file.csv");

It also provides an API that converts CSV files to Object Lists

var deserializer = new Valentine.ObjectDeserializer<Adw.Flap> ();
List<Adw.Flap> list = deserializer.deserializer_from_file ("/path/to/csv/file.csv");

Features

Support for property types:

  • Integers
  • Booleans
  • Strings
  • Chars
  • UChars
  • Longs
  • DateTimes
  • Files
  • Uint
  • Floats
  • Doubles
  • Variants
  • Flags
  • Enums
  • Possibility to add user defined functions to parse other types (such as custom classes)

Other features:

  • Save directly to a file
  • Parse CSV file and create an object with an expected type

libvalentine's People

Contributors

diego-ivan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

libvalentine's Issues

Performance Issues

Currently, the parser is fast enough to process >1000 objects at once. Nevertheless, the performance starts worsening from there.
In tests/adw_flap-test.vala, the following results have been obtained for the parsing process:

Objects Time Taken
2000 11 seconds
3000 27 seconds

Despite not being a particularly large amount of time, some improvements can be made. The branch /wip/performance-experiments-1 has the following results.

Objects Time Taken
2000 3.5 seconds
3000 7.5 seconds

Which is major improvement. More experiments will be done and the one that has the best performance will be kept.

Remove errors thrown at ObjectSerializer and ObjectDeserializer constructors and public methods (Maybe also get rid of Generics?)

I feel that was a quite weird API decision from mine. Maybe a requires (typeof(T).is_object ()) statement in the constructors and public methods is enough. In case of the ObjectDeserializer deserialize_from_file_method I feel its better to handle the error internally rather than throwing them when something fails. Maybe we can also get rid of generics and use a ListStore-ish API, with the creation method having the Object type as parameter, so we can still have access to the ParamSpec.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.