Language plugins : Implementation

Top Level

At top level, you need to include the header file.

#include "gnucap/lang_base.h"

If you want to be able to static link the plugin, or combine it with others, wrap it in an anonymous namespace.

namespace {
// all of your other code goes here
} // close the anonymous namespace
// end of file

Inside of there, you need to define a new class.

class LANG_SPECTRE : public LANGUAGE {
  std::string name()const {return "spectre";}
  bool case_insensitive()const {return false;}
  UNITS units()const {return uSI;}
public: // override virtual, used by callback
  std::string arg_front()const {return " ";}
  std::string arg_mid()const {return "=";}
  std::string arg_back()const {return "";}
public: // override virtual, called by commands
  void		parse_top_item(CS&, CARD_LIST*);
  DEV_COMMENT*	parse_comment(CS&, DEV_COMMENT*);
  DEV_DOT*	parse_command(CS&, DEV_DOT*);
  MODEL_CARD*	parse_paramset(CS&, MODEL_CARD*);
  MODEL_SUBCKT* parse_module(CS&, MODEL_SUBCKT*);
  COMPONENT*	parse_instance(CS&, COMPONENT*);
  std::string	find_type_in_string(CS&);
private: // override virtual, called by print_item
  void print_paramset(OMSTREAM&, const MODEL_CARD*);
  void print_module(OMSTREAM&, const MODEL_SUBCKT*);
  void print_instance(OMSTREAM&, const COMPONENT*);
  void print_comment(OMSTREAM&, const DEV_COMMENT*);
  void print_command(OMSTREAM& o, const DEV_DOT* c);
private: // local
  void print_args(OMSTREAM&, const CARD*);
} lang_spectre;

Then delcare one static instance of it and “INSTALL” it with the “DISPATCHER”.

	d(&language_dispatcher,, &lang_spectre);

In general, the names do not need to be unique. It is ok if another plugin has the same names.

However, the name() string above should be unique so you can find it.

gnucap/manual/tech/plugins/languages/top_level.txt · Last modified: 2015/12/11 15:39 (external edit)
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Run by Debian Driven by DokuWiki