yast2-core
|
Abstract base class of all YCP elements. More...
#include <YCPElement.h>
Public Member Functions | |
YCPValue | asValue () const |
virtual string | toString () const =0 |
virtual std::ostream & | toStream (std::ostream &str) const =0 |
virtual std::ostream & | toXml (std::ostream &str, int indent) const =0 |
virtual const YCPElementRep * | shallowCopy () const |
Protected Member Functions | |
YCPElementRep () | |
virtual | ~YCPElementRep () |
Private Member Functions | |
YCPElementRep & | operator= (const YCPElementRep &) |
YCPElementRep (const YCPElementRep &) | |
void | destroy () const |
const YCPElementRep * | clone () const |
Private Attributes | |
int | reference_counter |
Friends | |
class | YCPElement |
Abstract base class of all YCP elements.
There are some basic rules of memory managesment common to all YCPElementRep classes. If you call a constructor of any YCPElementRep subclass or if you call an add method, that adds elements to a YCPListRep, YCPTermRep YCPDeclTermRep or YCPBlockRep, and if this constructor or add method has arguments of type const YCPElementRep * (or of a subclass), then the responsibility for the values you gave for those arguments goes over to the object whose constructor or add function has been called. You may refer that object afterwards in any way. Therefore create the object either with new or with the YCPElementRep::clone method.
Example1:
YCPTermRep *term = new YCPTermRep (new YCPSymbolRep ("foo"));
Example2:
YCPSymbolRep sym ("foo"); YCPTermRep term (sym.clone ());
The second rule is that you never should delete any YCPElementRep object directly. Rather use the method YCPElementRep::destroy for that purpose. YCPElementRep::clone and YCPElementRep::destroy keep keep reference counter in order to decide, if any valid reference to the object exists. destroy calls delete when the last reference is dropped.
The third rule is about return values of the methods YCPElementRep and its subclasses. Member methods that return pointers to YCPElementRep subclasses simply return a pointer to the answer without increasing its reference counter. You must not destroy such an answer.
Example:
YCPTermRep *term = new YCPTermRep (new YCPSymbolRep ("foo")); cout << term->symbol ()->toString ();
If you want to keep the result beyond the scope of the object whose method you called, use YCPElementRep that create a valid reference to the returned object.
The fourth rule is: Pointers to YCPElementRep are always const with the only exception of YCPListRep, YCPDeclTermRep, YCPTermRep and YCPBlockRep who have an add member function that allows the parser to construct those objects element by element.
|
private |
Prevent implicite definition of copy constructor. Assignment of YCPElements is not possible nor allowed.
|
protected |
Initializes this object. Sets the to 1.
|
protectedvirtual |
Frees all resources used by this object. Never call this method directly (don't use delete). Rather use the member function destroy. It manages the reference counting.
YCPValue YCPElementRep::asValue | ( | ) | const |
Casts this element into a pointer of type YCPValueRep
|
private |
Gives you a new reference to this object. Increases the reference_counter. This method is delared const though it changes a member value - the reference_counter. But it is constant in that it doesn't change the YCP meaning of this YCPElementRep.
References reference_counter.
Referenced by YCPElement::operator=(), and YCPElement::writeCopy().
|
private |
Call this method instead of delete, when you have a pointer to a YCPElementRep that you don't need any longer. The data the YCPElementRep pointer points to may be shared data. This method handles reference counting and deletes the object when the reference counter drops to 0. Destroy is declared const, but of course changes the objects data. But it doesn't change the actual YCP value / meaning of the YCPElementRep.
References reference_counter, and y2internal.
Referenced by YCPElement::operator=(), YCPElement::writeCopy(), and YCPElement::~YCPElement().
|
private |
Prevent implicite definition of assignment. Assignment of YCPElements is not possible nor allowed.
|
inlinevirtual |
Returns a shallow copy of this elementRep. Redefine this method to implement copy on write.
Reimplemented in YCPListRep, YCPTermRep, and YCPMapRep.
Referenced by YCPElement::writeCopy().
|
pure virtual |
Writes the value to a stream in bytecode format.
Implemented in YCPReferenceRep, YCPEntryRep, YCPReturnRep, YCPListRep, YCPPathRep, YCPMapRep, YCPBreakRep, YCPTermRep, YCPStringRep, YCPByteblockRep, YCPFloatRep, YCPSymbolRep, YCPBooleanRep, YCPIntegerRep, YCPCodeRep, YCPExternalRep, and YCPVoidRep.
|
pure virtual |
Returns the ASCII representation of this element. This representation can be parsed with ycp_parse to create an object whose value is identical to the value of this object.
Implemented in YCPReferenceRep, YCPEntryRep, YCPReturnRep, YCPListRep, YCPPathRep, YCPMapRep, YCPBreakRep, YCPTermRep, YCPStringRep, YCPByteblockRep, YCPFloatRep, YCPSymbolRep, YCPBooleanRep, YCPIntegerRep, YCPCodeRep, YCPExternalRep, and YCPVoidRep.
Referenced by YCPValueRep::asBoolean(), YCPValueRep::asByteblock(), YCPValueRep::asCode(), YCPValueRep::asEntry(), YCPValueRep::asExternal(), YCPValueRep::asFloat(), YCPValueRep::asInteger(), YCPValueRep::asList(), YCPValueRep::asMap(), YCPValueRep::asPath(), YCPValueRep::asReference(), YCPValueRep::asString(), YCPValueRep::asSymbol(), YCPValueRep::asTerm(), YCPValueRep::asVoid(), and YCPValueRep::compare().
|
pure virtual |
Implemented in YCPReferenceRep, YCPEntryRep, YCPValueRep, YCPReturnRep, YCPListRep, YCPPathRep, YCPMapRep, YCPBreakRep, YCPTermRep, YCPStringRep, YCPByteblockRep, YCPFloatRep, YCPSymbolRep, YCPBooleanRep, YCPIntegerRep, YCPCodeRep, YCPExternalRep, and YCPVoidRep.
|
friend |
|
mutableprivate |
Counts the references for this value. Each time the clone method is called, the reference counter is increased. The destroy method decreases the reference counter and deletes the object, if the counter drops to 0.
Referenced by clone(), destroy(), and YCPElement::writeCopy().