import { Texts } from "../library/Texts"; import { VariationDefinitions } from "./VariationTemplates"; export type MemberDefinitions = { [index:string]:any }; export class CppDefinition { variations:string|VariationDefinitions; class:string; includes:string[]; forwards:string[]; public:MemberDefinitions; protected:MemberDefinitions; static createVariation( cppDefinition:CppDefinition, map:Map ):CppDefinition { let variation = new CppDefinition(); variation.class = Texts.replaceAll( cppDefinition.class, map ); variation.includes = Texts.replaceAllIn( cppDefinition.includes, map ); variation.forwards = Texts.replaceAllIn( cppDefinition.forwards, map ); variation.public = CppDefinition.applyVariationOnAll( cppDefinition.public, map ); variation.protected = CppDefinition.applyVariationOnAll( cppDefinition.protected, map ); return variation; } static applyVariationOnAll( obj:T, map:Map ):T { if ( obj === null || obj === undefined ) { return obj; } let jsonValue = JSON.stringify( obj ); jsonValue = Texts.replaceAll( jsonValue, map ); return JSON.parse( jsonValue ) as T; } }