Skip to content
/ scv Public

Utility program for reducing the cost of writing C++ boilerplate code. SCV ready! 🏭

Notifications You must be signed in to change notification settings

atemmel/scv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scv

SCV is a utility program intended to reduce the cost of writing C++ boilerplate code. Regular C++ templates are powerful, but they lack certain features that are useful for serialization of data.

Concepts

Macros

Keywords prefixed with an @ are considered SCV macros. Available macros are as follows:

  • @Type - Substitute for the active type of a macro specification
  • @ForMemberInType - Iterates over the members within a type
  • @Member - Substitue for the active member within the type iterated upon

Traits

Traits are a way to design generic behaviour for several datatypes. Below is an example of a trait that can be used to generate an operator<< implementation for basic POD structs.

trait Printable requires <iostream> {
code {
std::ostream& operator<<(std::ostream& os, const @Type& value) {
  @ForMemberIn(@Type) code {
    os << value.@Member << ' ';
  }
  return os;
}
}
}

Structs

Structs are (mostly) what one would expect, with the added option of specifying which traits a given struct may wish to implement.

// message.scv

struct Message is printable {
	int type
	string contents
	string destination
	u64 validFrom
	u64 validUntil
	float scale
	bool sentFromAdmin
}

Example usage

After designing a spec for your data and available operations, run the program once to generate the corresponding header files.

./scv message.scv

You now have valid C++ code.

// messsage.hpp
// File autogenerated by scv on: 2021-07-05 10:50:05

#pragma once

#include <string>
#include <iostream>

struct Message {
	int type;
	std::string contents;
	std::string destination;
	uint64_t validFrom;
	uint64_t validUntil;
	float scale;
	bool sentFromAdmin;
};

std::ostream& operator<<(std::ostream& os, const Message& value) {
	os << value.type << ' ';
os << value.contents << ' ';
os << value.destination << ' ';
os << value.validFrom << ' ';
os << value.validUntil << ' ';
os << value.scale << ' ';
os << value.sentFromAdmin << ' ';
return os;
}

About

Utility program for reducing the cost of writing C++ boilerplate code. SCV ready! 🏭

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published