Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [XML] Assertion when GetAttrCount()
[XML] Assertion when GetAttrCount() [message #6906] Mon, 04 December 2006 08:29 Go to next message
g00fy is currently offline  g00fy
Messages: 15
Registered: December 2006
Location: Mechelen, Belgium, Europe
Promising Member
#include <CtrlLib/CtrlLib.h>
#include <ide/Common/Common.h>
#include <Core/Core.h>


void write_out( FileOut& out, const XmlNode& xml, int ident )
{
	switch( xml.GetType() )
	{
	case XML_TEXT:
		out << String(' ', ident) << "Text: " << xml.GetText() << "\n";
		break;
	case XML_TAG:
		out << String(' ', ident) << "Tag: " << xml.GetTag() << "\n";
		for ( int i = 0, total = xml.GetAttrCount(); i < total; i++ )
		{
			out << String( ' ', ident ) << "+> " << xml.AttrId(i) << ": " << xml.Attr(i) << "\n";
		}
		ident += 2;
		break;
	case XML_DOC:
		out << String(' ', ident) << "Doc:\n";
		break;
	default:
		out << String(' ', ident) << "**UNDEFINED TAG**\n";
		break;
	}
	
	for ( int i = 0, total = xml.GetCount(); i < total; i++ )
	{
		write_out(out, xml[i], ident + 2);
	}
}

GUI_APP_MAIN
{
	Package p;

	String filename("C:\\Upp\\uppsrc\\ide\\Common\\Common.upp");

	p.Load(filename);
	
	XmlNode xml;

	XmlNode makefile = xml.Add("makefile");
	
	XmlNode lib = makefile.Add("lib");
	lib.SetAttr("id", GetFileName(filename));
	
	FileOut out("c:\\tst.dat");
	write_out(out, xml, 2);
}


This code asserts on the call to "xml.GetAttrCount()". It thinks the vector holding those items have -1 items only...

Greetz
Re: [XML] Assertion when GetAttrCount() [message #6934 is a reply to message #6906] Tue, 05 December 2006 13:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
g00fy wrote on Mon, 04 December 2006 02:29

#include <CtrlLib/CtrlLib.h>
#include <ide/Common/Common.h>
#include <Core/Core.h>




U++ headers are always arranged so that "higher" include "lower", means "#include <ide/Common/Common.h>" is enough here.

Quote:


This code asserts on the call to "xml.GetAttrCount()". It thinks the vector holding those items have -1 items only...



-1 in items is generally the sign of broken pick semantics. Indeed:

	XmlNode makefile = xml.Add("makefile");
	
	XmlNode lib = makefile.Add("lib");


Here you pick "makefile" node out of xml and "lib" out of makefile. This is basically "java style code"...

In U++ we are usually referencing objects created inside complex structures:

	XmlNode& makefile = xml.Add("makefile");
	
	XmlNode& lib = makefile.Add("lib");


These are basic paradigms of U++ - perhaps unusual for newcomers, but in the end this is a way how to keep things simple and deterministic (and avoid smart pointers and GC wishes...)

Mirek
Re: [XML] Assertion when GetAttrCount() [message #7017 is a reply to message #6934] Fri, 08 December 2006 01:50 Go to previous messageGo to next message
g00fy is currently offline  g00fy
Messages: 15
Registered: December 2006
Location: Mechelen, Belgium, Europe
Promising Member
I like smartpointers! They keep my memory organised Smile
Re: [XML] Assertion when GetAttrCount() [message #7023 is a reply to message #7017] Fri, 08 December 2006 09:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
g00fy wrote on Thu, 07 December 2006 19:50

I like smartpointers! They keep my memory organised Smile


Well, you will not like U++ then....

U++ has all resources very organised - but without smart pointers. Core U++ paradigms are:

- GC is bad idea
- Shared reference counted pointers is even worse idea
- Manually releasing resources is absolutely stupid idea

Smile

Mirek
Re: [XML] Assertion when GetAttrCount() [message #7027 is a reply to message #7023] Fri, 08 December 2006 10:02 Go to previous messageGo to next message
g00fy is currently offline  g00fy
Messages: 15
Registered: December 2006
Location: Mechelen, Belgium, Europe
Promising Member
Could you underbuidl your statements please? I would like to learn a thing or two Smile.

Or just point me to some website stating that?

Garbage collection is not really bad, it just makes your memory go 'boom'. But referenced shared pointer is generally a good idea imho.
Re: [XML] Assertion when GetAttrCount() [message #7036 is a reply to message #7027] Fri, 08 December 2006 11:42 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
g00fy wrote on Fri, 08 December 2006 04:02

Could you underbuidl your statements please? I would like to learn a thing or two Smile.

Or just point me to some website stating that?



No, that is *U++* paradigm. So the only website I can point you to is ours Wink (see http://www.ultimatepp.org/www$uppweb$overview$en-us.html)

In fact, I think this is the main difference between U++ and the rest of the world.

The rest of the world insists that you absolutely do need at least of these three things in your code (I mean you need either GC or shared pointers or delete things manually).

U++ proves that you don't Smile

Quote:


Garbage collection is not really bad, it just makes your memory go 'boom'. But referenced shared pointer is generally a good idea imho.


It is the nice *idea* (just like STL Smile. But avoiding it is even better Wink

BTW, do not get me wrong - U++ also uses reference counting here and there, but only as implementation detail - does not expose it at interface level. That is major difference.

Mirek
Previous Topic: Bug in "Streams" documentation (Serialization support)?
Next Topic: Value: BOOLEAN_V, USERVALUE_V [REQUEST]
Goto Forum:
  


Current Time: Sat Apr 27 18:23:51 CEST 2024

Total time taken to generate the page: 0.04496 seconds