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.
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 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 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
}After designing a spec for your data and available operations, run the program once to generate the corresponding header files.
./scv message.scvYou 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;
}