OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
PrintString Class Reference

#include <AssemblerParser.hh>

Collaboration diagram for PrintString:
Collaboration graph

Public Member Functions

 PrintString (const char *aStr)
 PrintString actor. More...
 
 PrintString (std::string &string)
 
void operator() (const char *, const char *) const
 

Private Attributes

const char * str_
 

Detailed Description

Something about functors from Sprit manual (those little classes below that can be used as like callback functions with Spirit).

With functors, take note that the operator() should be const. This implies that functors are immutable. One may wish to have some member variables that are modified when the action gets called. This is not a good idea. First of all, functors are preferably lightweight. Functors are passed around a lot and it would incur a lot of overhead if the functors are heavily laden. Second, functors are passed by value. Thus, the actual functor object that finally attaches to the parser, will surely not be the original instance supplied by the client. What this means is that changes to a functor's state will not affect the original functor that the client passed in since they are distinct copies. If a functor needs to update some state variables, which is often the case, it is better to use references to external data.

Personal notes:

I preferred to use predefined functors, which can do some stl container operations and assignments...

I came across with few problems with spirit, I tried to do parser that would have used pointer assignments and dynamic binding. Parser seems to hard code some addresses, because address pointers and copy parameters didn't seen to work too well.

Here is some examples that didn't work.

[assign_a(pointer, &object)] in this case I tried to set destination for parsing to be object. I manage do this kind of assignment when I wrote special actor for that.

[assign_a(pointer->structField)] This doesn't work either. If you want to set field through pointer, you have to create actor for that.

Copying by passing pointers and references and and dynamic binding is seems to be possible with Spirit, but you have to write a lot more code. So I always copied parsed values that I used. Prints given string to std::cerr. Used for syntax error.

Definition at line 195 of file AssemblerParser.hh.

Constructor & Destructor Documentation

◆ PrintString() [1/2]

PrintString::PrintString ( const char *  aStr)

PrintString actor.

Constructor of actor.

Parameters
aStrString to print.

Definition at line 54 of file AssemblerParser.cc.

54  : str_(aStr) {
55 }

◆ PrintString() [2/2]

PrintString::PrintString ( std::string &  aStr)

Constructor of actor.

Parameters
aStrString to print.

Definition at line 63 of file AssemblerParser.cc.

63  : str_(aStr.c_str()) {
64 }

Member Function Documentation

◆ operator()()

void PrintString::operator() ( const char *  ,
const char *   
) const

Prints out string of actor.

Definition at line 70 of file AssemblerParser.cc.

70  {
71  std::cerr << str_;
72 }

References str_.

Member Data Documentation

◆ str_

const char* PrintString::str_
private

Definition at line 202 of file AssemblerParser.hh.

Referenced by operator()().


The documentation for this class was generated from the following files:
PrintString::str_
const char * str_
Definition: AssemblerParser.hh:202