combineHead()

in src/langs/cpp/combinator.js [171:210]


  combineHead(objects) {
    const models = objects.filter(obj => obj.type === 'model');
    const [client] = objects.filter(obj => obj.type === 'client');
    const outputPars = { head: '', body: '', foot: '' };

    /******************************* emit body *******************************/
    let emitter = new Emitter(this.config);
    emitter.emitln(`namespace ${this.namespace} {`);
    this.definedModels = [];
    this.models = models;
    // Fix the problem when used before definition
    models.forEach(model => this.emitModel(emitter, model));
    this.emitClass(emitter, client);
    emitter.emitln(`} // namespace ${this.namespace}`);
    outputPars.body = emitter.output;

    /******************************* emit head *******************************/
    emitter = new Emitter(this.config);
    if (client.topAnnotation.length > 0) {
      this.emitAnnotations(emitter, client.topAnnotation);
      emitter.emitln();
    }
    const headerName = `${this.namespace}_H_`.toUpperCase();
    emitter.emitln(`#ifndef ${headerName}`);
    emitter.emitln(`#define ${headerName}`).emitln();
    this.emitInclude(emitter);
    outputPars.head = emitter.output;

    /******************************* emit foot   *******************************/
    emitter = new Emitter(this.config);
    emitter.emitln().emitln('#endif');
    outputPars.foot = emitter.output;

    /***************************** combine output ******************************/
    const config = _deepClone(this.config);
    config.ext = '.' + this.config.header_ext;
    config.dir = `${config.dir}/include/${_toSnakeCase(this.scope)}`;
    config.filename = _toSnakeCase(this.package);
    this.combineOutputParts(config, outputPars);
  }