Browse Source

Einiege Fehler behoben

kolja 5 years ago
parent
commit
75d68ab0a1
5 changed files with 145 additions and 108 deletions
  1. 5 5
      CharMap.h
  2. 1 1
      Text.cpp
  3. 19 6
      Trie.h
  4. 117 93
      UIMLView.cpp
  5. 3 3
      XML.cpp

+ 5 - 5
CharMap.h

@@ -14,7 +14,7 @@ namespace Framework
         CharMap()
         {
             entries = new T*[ 256 ];
-            for( int i = 0; i < 156; i++ )
+            for( int i = 0; i < 256; i++ )
                 entries[ i ] = 0;
             value = 0;
             ref = 1;
@@ -22,7 +22,7 @@ namespace Framework
 
         ~CharMap()
         {
-            for( int i = 0; i < 156; i++ )
+            for( int i = 0; i < 256; i++ )
             {
                 if( entries[ i ] )
                     entries[ i ]->release();
@@ -32,17 +32,17 @@ namespace Framework
                 value->release();
         }
 
-        T *get( char c )
+        T *get( unsigned char c )
         {
             return entries[ (int)c ] ? entries[ (int)c ]->getThis() : 0;
         }
 
-        T *z( char c )
+        T *z( unsigned char c )
         {
             return entries[ (int)c ];
         }
 
-        void set( char c, T *t )
+        void set( unsigned char c, T *t )
         {
             if( entries[ (int)c ] )
                 entries[ (int)c ]->release();

+ 1 - 1
Text.cpp

@@ -659,7 +659,7 @@ void Text::remove( int i, Text *t )
 void Text::removeWhitespaceAfter( int pos )
 {
     int length = 0;
-    for( int i = pos; i < txt[ i ]; i++ )
+    for( int i = pos; txt[ i ]; i++ )
     {
         if( txt[ i ] == ' ' || txt[ i ] == '\n' || txt[ i ] == '\r' || txt[ i ] == '\t' )
             length++;

+ 19 - 6
Trie.h

@@ -39,6 +39,18 @@ namespace Framework
             delete parent;
         }
 
+        TrieIteratorData &operator=( TrieIteratorData &data )
+        {
+            map = data.map;
+            TrieIteratorData *tmp = parent;
+            if( data.parent )
+                parent = new TrieIteratorData( *data.parent );
+            else
+                parent = 0;
+            delete tmp;
+            return *this;
+        }
+
         void set( CharMap< Trie< T >, T > *zMap, TrieIteratorData parent )
         {
             map = zMap;
@@ -62,29 +74,30 @@ namespace Framework
         TrieIterator next()
         {
             Trie<T> *n = 0;
-            for( char i = 0; i < 256; i++ )
+            for( int i = 0; i < 256; i++ )
             {
                 if( data.map->z( i ) )
                     return TrieIterator( TrieIteratorData<T>( data.map->z( i )->map, data ) );
             }
-            if( !data.parent )
+            if( !data.parent || !data.parent->map )
                 return TrieIterator( TrieIteratorData<T>( 0, TrieIteratorData<T>() ) );
             TrieIteratorData<T> d = data;
             do
             {
-                for( char i = 0; i < 256; i++ )
+                for( int i = 0; i < 256; i++ )
                 {
-                    if( d.parent->map->z( i )->map == d.map )
+                    if( d.parent->map->z( i ) && d.parent->map->z( i )->map == d.map )
                     {
-                        for( char j = i + 1; j < 256; j++ )
+                        for( int j = i + 1; j < 256; j++ )
                         {
                             if( d.parent->map->z( j ) )
                                 return TrieIterator( TrieIteratorData<T>( d.parent->map->z( j )->map, *d.parent ) );
                         }
                         d = *d.parent;
+                        break;
                     }
                 }
-            } while( d.parent );
+            } while( d.parent && d.parent->map );
             return TrieIterator( TrieIteratorData<T>( 0, TrieIteratorData<T>() ) );
         }
 

+ 117 - 93
UIMLView.cpp

@@ -147,131 +147,152 @@ Zeichnung *UIMLView::parseElement( XML::Element *e )
 
 void UIMLView::layout( XML::Element *e )
 {
-    if( e->hasAttribute( "width" ) )
+    Text id = e->getAttributeValue( "id" );
+    Zeichnung *z = members->z( id );
+    if( z )
     {
-        Text id = e->getAttributeValue( "id" );
-        Zeichnung *z = members->z( id );
-        if( z )
+        int width = z->getBreite();
+        int height = z->getHeight();
+        if( e->hasAttribute( "width" ) )
         {
-            int width = z->getBreite();
-            int height = z->getHeight();
-            if( e->hasAttribute( "width" ) )
-            {
-                Text w = e->getAttributeValue( "width" );
-                width = w;
-                if( w.getText()[ w.getLength() - 1 ] == '%' )
-                    width = ( getBreite() / 100 ) * width;
-            }
-            if( e->hasAttribute( "height" ) )
-            {
-                Text h = e->getAttributeValue( "height" );
-                height = h;
-                if( h.getText()[ h.getLength() - 1 ] == '%' )
-                    height = ( getHeight() / 100 ) * height;
-            }
-            z->setSize( width, height );
-            if( e->hasAttribute( "align-left" ) )
+            Text w = e->getAttributeValue( "width" );
+            width = w;
+            if( w.getText()[ w.getLength() - 1 ] == '%' )
+                width = ( getBreite() / 100 ) * width;
+        }
+        if( e->hasAttribute( "height" ) )
+        {
+            Text h = e->getAttributeValue( "height" );
+            height = h;
+            if( h.getText()[ h.getLength() - 1 ] == '%' )
+                height = ( getHeight() / 100 ) * height;
+        }
+        z->setSize( width, height );
+        if( e->hasAttribute( "align-left" ) )
+        {
+            Text la = e->getAttributeValue( "align-left" );
+            int x;
+            if( la.istGleich( "start" ) )
+                x = 0;
+            else if( la.istGleich( "end" ) )
+                x = getBreite();
+            else
             {
-                Text la = e->getAttributeValue( "align-left" );
                 XML::Editor ed = e->zParent()->selectChildsByAttribute( "id", la );
                 for( auto i = ed.getIterator(); i; i++ )
                     layout( i );
                 Zeichnung *laz = members->z( la );
                 if( laz )
-                {
-                    int x = laz->getX() + laz->getBreite();
-                    if( e->hasAttribute( "margin-left" ) )
-                    {
-                        Text mt = e->getAttributeValue( "margin-left" );
-                        int m = mt;
-                        if( mt.getText()[ mt.getLength() - 1 ] == '%' )
-                            m = ( getBreite() / 100 ) * m;
-                        x += m;
-                    }
-                    z->setX( x );
-                }
+                    x = laz->getX() + laz->getBreite();
             }
-            else if( e->hasAttribute( "align-right" ) )
+            if( e->hasAttribute( "margin-left" ) )
+            {
+                Text mt = e->getAttributeValue( "margin-left" );
+                int m = mt;
+                if( mt.getText()[ mt.getLength() - 1 ] == '%' )
+                    m = ( getBreite() / 100 ) * m;
+                x += m;
+            }
+            z->setX( x );
+        }
+        else if( e->hasAttribute( "align-right" ) )
+        {
+            Text ra = e->getAttributeValue( "align-right" );
+            int x;
+            if( ra.istGleich( "start" ) )
+                x = -z->getBreite();
+            else if( ra.istGleich( "end" ) )
+                x = getBreite() - z->getBreite();
+            else
             {
-                Text ra = e->getAttributeValue( "align-right" );
                 XML::Editor ed = e->zParent()->selectChildsByAttribute( "id", ra );
                 for( auto i = ed.getIterator(); i; i++ )
                     layout( i );
                 Zeichnung *raz = members->z( ra );
                 if( raz )
-                {
-                    int x = raz->getX() - z->getBreite();
-                    if( e->hasAttribute( "margin-left" ) )
-                    {
-                        Text mt = e->getAttributeValue( "margin-right" );
-                        int m = mt;
-                        if( mt.getText()[ mt.getLength() - 1 ] == '%' )
-                            m = ( getBreite() / 100 ) * m;
-                        x -= m;
-                    }
-                    z->setX( x );
-                }
+                    x = raz->getX() - z->getBreite();
             }
-            if( e->hasAttribute( "align-top" ) )
+            if( e->hasAttribute( "margin-right" ) )
+            {
+                Text mt = e->getAttributeValue( "margin-right" );
+                int m = mt;
+                if( mt.getText()[ mt.getLength() - 1 ] == '%' )
+                    m = ( getBreite() / 100 ) * m;
+                x -= m;
+            }
+            z->setX( x );
+        }
+        if( e->hasAttribute( "align-top" ) )
+        {
+            Text ta = e->getAttributeValue( "align-top" );
+            int y;
+            if( ta.istGleich( "start" ) )
+                y = 0;
+            else if( ta.istGleich( "end" ) )
+                y = getHeight();
+            else
             {
-                Text ta = e->getAttributeValue( "align-top" );
                 XML::Editor ed = e->zParent()->selectChildsByAttribute( "id", ta );
                 for( auto i = ed.getIterator(); i; i++ )
                     layout( i );
                 Zeichnung *taz = members->z( ta );
                 if( taz )
-                {
-                    int y = taz->getY() + taz->getHeight();
-                    if( e->hasAttribute( "margin-top" ) )
-                    {
-                        Text mt = e->getAttributeValue( "margin-top" );
-                        int m = mt;
-                        if( mt.getText()[ mt.getLength() - 1 ] == '%' )
-                            m = ( getHeight() / 100 ) * m;
-                        y += m;
-                    }
-                    z->setY( y );
-                }
+                    y = taz->getY() + taz->getHeight();
             }
-            else if( e->hasAttribute( "align-bottom" ) )
+            if( e->hasAttribute( "margin-top" ) )
+            {
+                Text mt = e->getAttributeValue( "margin-top" );
+                int m = mt;
+                if( mt.getText()[ mt.getLength() - 1 ] == '%' )
+                    m = ( getHeight() / 100 ) * m;
+                y += m;
+            }
+            z->setY( y );
+        }
+        else if( e->hasAttribute( "align-bottom" ) )
+        {
+            Text ba = e->getAttributeValue( "align-bottom" );
+            int y;
+            if( ba.istGleich( "start" ) )
+                y = -z->getHeight();
+            else if( ba.istGleich( "end" ) )
+                y = getHeight() - z->getHeight();
+            else
             {
-                Text ba = e->getAttributeValue( "align-bottom" );
                 XML::Editor ed = e->zParent()->selectChildsByAttribute( "id", ba );
                 for( auto i = ed.getIterator(); i; i++ )
                     layout( i );
                 Zeichnung *baz = members->z( ba );
                 if( baz )
-                {
-                    int y = baz->getY() - z->getHeight();
-                    if( e->hasAttribute( "margin-bottom" ) )
-                    {
-                        Text mt = e->getAttributeValue( "margin-bottom" );
-                        int m = mt;
-                        if( mt.getText()[ mt.getLength() - 1 ] == '%' )
-                            m = ( getHeight() / 100 ) * m;
-                        y -= m;
-                    }
-                    z->setY( y );
-                }
+                    y = baz->getY() - z->getHeight();
             }
-            int x = z->getX();
-            int y = z->getY();
-            if( e->hasAttribute( "x" ) )
+            if( e->hasAttribute( "margin-bottom" ) )
             {
-                Text xt = e->getAttributeValue( "x" );
-                x = xt;
-                if( xt.getText()[ xt.getLength() - 1 ] == '%' )
-                    x = ( getBreite() / 100 ) * x;
+                Text mt = e->getAttributeValue( "margin-bottom" );
+                int m = mt;
+                if( mt.getText()[ mt.getLength() - 1 ] == '%' )
+                    m = ( getHeight() / 100 ) * m;
+                y -= m;
             }
-            if( e->hasAttribute( "y" ) )
-            {
-                Text yt = e->getAttributeValue( "y" );
-                y = yt;
-                if( yt.getText()[ yt.getLength() - 1 ] == '%' )
-                    y = ( getHeight() / 100 ) * y;
-            }
-            z->setPosition( x, y );
+            z->setY( y );
+        }
+        int x = z->getX();
+        int y = z->getY();
+        if( e->hasAttribute( "x" ) )
+        {
+            Text xt = e->getAttributeValue( "x" );
+            x = xt;
+            if( xt.getText()[ xt.getLength() - 1 ] == '%' )
+                x = ( getBreite() / 100 ) * x;
+        }
+        if( e->hasAttribute( "y" ) )
+        {
+            Text yt = e->getAttributeValue( "y" );
+            y = yt;
+            if( yt.getText()[ yt.getLength() - 1 ] == '%' )
+                y = ( getHeight() / 100 ) * y;
         }
+        z->setPosition( x, y );
     }
 }
 
@@ -297,7 +318,6 @@ void UIMLView::setUIML( XML::Element *uiml )
 //  uiml: Ein xml text gemät des ksg uiml standarts
 void UIMLView::setUIML( Text uiml )
 {
-    uiml.toLowerCase();
     setUIML( new XML::Element( uiml ) );
 }
 
@@ -329,6 +349,7 @@ void UIMLView::doMausEreignis( MausEreignis &me )
     me.verarbeitet = verarbeitet;
     for( auto i = members->getIterator(); i; i++ )
     {
+        // TODO consider only first level childs
         if( i._ )
         {
             i->doMausEreignis( me );
@@ -345,6 +366,7 @@ void UIMLView::doTastaturEreignis( TastaturEreignis &te )
     te.verarbeitet = verarbeitet;
     for( auto i = members->getIterator(); i; i++ )
     {
+        // TODO consider only first level childs
         if( i._ )
         {
             i->doTastaturEreignis( te );
@@ -359,6 +381,7 @@ bool UIMLView::tick( double tickVal )
 {
     for( auto i = members->getIterator(); i; i++ )
     {
+        // TODO tick only first level childs
         if( i._ )
         {
             rend |= i->tick( tickVal );
@@ -373,6 +396,7 @@ void UIMLView::render( Bild &rObj )
     ZeichnungHintergrund::render( rObj );
     for( auto i = members->getIterator(); i; i++ )
     { // TODO render elements backwards
+        // TODO render only first level childs
         if( i._ )
         {
             i->render( rObj );

+ 3 - 3
XML.cpp

@@ -32,7 +32,7 @@ Element::Element( Text string, Element *zParent )
         {
             if( ( string[ i ] < 'a' || string[ i ] > 'z' ) &&
                 ( string[ i ] < 'A' || string[ i ] > 'Z' ) &&
-                ( string[ i ] < '0' || string[ i ] > '9' ) )
+                ( string[ i ] < '0' || string[ i ] > '9' ) && string[ i ] != '-' )
             {
                 nameEnd = i;
                 break;
@@ -50,7 +50,7 @@ Element::Element( Text string, Element *zParent )
                 {
                     if( ( string[ i ] < 'a' || string[ i ] > 'z' ) &&
                         ( string[ i ] < 'A' || string[ i ] > 'Z' ) &&
-                        ( string[ i ] < '0' || string[ i ] > '9' ) )
+                        ( string[ i ] < '0' || string[ i ] > '9' ) && string[ i ] != '-' )
                     {
                         nameEnd = i;
                         break;
@@ -439,7 +439,7 @@ Text Element::getAttributeValue( Text attribut ) const
 {
     for( auto i = attributes->getIterator(), j = attributeValues->getIterator(); i && j; i++, j++ )
     {
-        if( i->istGleich( name ) )
+        if( i->istGleich( attribut ) )
             return j->getText();
     }
     return "";