/** * Generate variable definition code * * @return string C++ code */ public function getCode() { if (!is_null($this->variable)) { $type = $this->variable->isOneType(); if ($type) { switch ($type) { case Type::TYPE_INT: $this->type = self::TYPE_INT; break; case Type::TYPE_FLOAT: $this->type = self::TYPE_FLOAT; break; case Type::TYPE_STRING: $this->type = self::TYPE_STRING; break; } } } if (!is_null($this->argumentNum)) { if (is_null($this->argumentDefaultValue)) { $argument = ' = args[' . $this->argumentNum . ']'; } else { $argument = '; if(args.size() > ' . $this->argumentNum . ') phpVar_' . $this->name . ' = args[' . $this->argumentNum . ']; else phpVar_' . $this->name . ' = ' . $this->argumentDefaultValue . ' '; } } else { if ($this->type == self::TYPE_INT) { $argument = ' = 0'; } elseif ($this->type == self::TYPE_FLOAT) { $argument = ' = 0.0'; } else { $argument = ' = nullptr'; } } $this->type = str_replace('%varClass%', self::$varClass, $this->type); return "\t" . $this->type . ' phpVar_' . $this->name . $argument . ';' . "\n"; }