Does vJass support anonymous classes?

krainert

Member
Reaction score
10
Does it?
Otherwise the iterator for my improved hash map will have to rely on some pretty nasty coding (making index-based access to entries in hash tables public, oh the horror) :)
EDIT: Also, does vJass support a protected (Java style) access level modifier? That ought to help in case I can't use anonymous classes!
EDIT: There was something else I wanted to ask, but I forgot... Hopefully this note will remind me once I get back.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
krainert:
1. Also, does vJass support a protected (Java style) access level modifier? That ought to help in case I can't use anonymous classes!

1. I don't think so.

I am not sure what you mean by hash map but you can look at the Table library which might already do what you're doing.
 

tooltiperror

Super Moderator
Reaction score
231
Also, for set and get:
JASS:
struct Data
    readonly integer x

    method setX takes integer newX returns nothing
        if (newX >= 0) then
            set x = newX
        endif
    endmethod

    method getX takes nothing returns integer
        return x
    endmethod
endstruct

Faux-set/get functions :)
 

SerraAvenger

Cuz I can
Reaction score
234
JASS:
struct data
    readonly integer priv_x

    method operator x= takes integer ax returns nothing
        if (ax >= 0) then
            set priv_x = ax
        endif
    endmethod

    method operator x takes nothing returns integer
        return priv_x
    endmethod
endstruct


http://www.wc3c.net/vexorian/jasshelpermanual.html#operover


Also, you might want to do something like this:

JASS:
//! textmacro Z_ITERATION takes MOD, TYPE
    $MOD$ interface iteration_$TYPE$ {
        method getNext() -> iteration_$TYPE$;
        method hasNext() -> boolean;
        method getValue() -> $TYPE$;
    }
    
    $MOD$ interface iterable_$TYPE$ {
        method iteration() -> iteration_$TYPE$;
        method size() -> integer;
    }
//! endtextmacro


Which can be used like this:

JASS:
// ...

    //! runtextmacro Z_ITERATION("","cop")
    //! runtextmacro Z_LINKED_LIST("","cop")

    ll_cop cops;
    
// ...
     TriggerAddAction(EnterRegion,function() {
            region enteredRegion = GetTriggeringRegion();
            cop entered;
            iteration_cop iter = cops.iteration();
            while (iter.hasNext()) {
                iter = iter.getNext();
                if (iter.getValue().circleRegion == enteredRegion)
                    enterRegion(GetEnteringUnit(),iter.getValue());
            }
        });
// ...


Using this linked list implementation:

JASS:
//! textmacro Z_LINKED_LIST takes MOD,TYPE
    $MOD$ struct ll_element_$TYPE$ extends iteration_$TYPE$ {
        $TYPE$ value;
        ll_element_$TYPE$ next = 0;
        ll_element_$TYPE$ last = 0;
        
        static method createIteration() -> thistype {
            thistype this = allocate();
            return this;
        }
        
        static method createHead(ll_element_$TYPE$ anext, $TYPE$ avalue) -> thistype {
            thistype this = allocate();
            value = avalue;
            next = anext;
            next.last = this;
            return this;
        }
        static method createTail(ll_element_$TYPE$ alast, $TYPE$ avalue) -> thistype {
            thistype this = allocate();
            value = avalue;
            last = alast;
            last.next = this;
            return this;
        }
    
        method getNext() -> iteration_$TYPE$ {
            return next;
        }
        method hasNext() -> boolean {
            return next != 0;
        }
        method getValue() -> $TYPE$ {
            return value;
        }
        
        method onDestroy() {
            last.next = next;
            next.last = last;
        }
        
        
        method destroyHead() ->  $TYPE$ {
            destroy();
            return value;
        }
        
        method destroyTail() ->  $TYPE$ {
            destroy();
            return value;
        }
    }
    
    $MOD$ struct ll_$TYPE$ extends iterable_$TYPE$ {
        ll_element_$TYPE$ head = 0;
        ll_element_$TYPE$ tail = 0;
        integer currentSize;
        ll_element_$TYPE$ headIterator = 0;
        
        method addLast($TYPE$ value) {
            tail = ll_element_$TYPE$.createTail(tail, value);
            if (head==0)
                head = tail;
            currentSize += 1;
        }
        
        method addFirst($TYPE$ value) {
            head = ll_element_$TYPE$.createHead(head, value);
            if (tail==0)
                tail = head;
            currentSize += 1;
        }
        
        
        method removeFirstValue($TYPE$ value) {
            iteration_$TYPE$ iter = iteration();
            while (iter.hasNext()) {
                iter = iter.getNext();
                if (iter.getValue() == value) {
                    currentSize -= 1;
                    iter.destroy();
                    break;
                }
            }
        }
        
        method removeLast() -> $TYPE$ {
            ll_element_$TYPE$ oldTail = tail;
            tail = tail.last;
            if (tail==0)
                head = 0;
            currentSize -= 1;
            return oldTail.destroyHead();
        }
        
        method removeFirst() -> $TYPE$ {
            ll_element_$TYPE$ oldHead = head;
            head = head.next;
            if (head==0)
                tail = 0;
            currentSize -= 1;
            return oldHead.destroyHead();
        }
        
        method getFirst() -> $TYPE$ {
            return head.getValue();
        }
        method getLast() -> $TYPE$ {
            return tail.getValue();
        }
        
        
        method enqueue($TYPE$ value) {
            addFirst(value);
        }
        method dequeue() -> $TYPE$ {
            return removeLast();
        }
        method push($TYPE$ value) {
            addFirst(value);
        }
        method pop() -> $TYPE$ {
            return removeFirst();
        }
        
        method iteration() -> iteration_$TYPE$ {
            if (headIterator == 0)
                headIterator = ll_element_$TYPE$.createIteration();
            
            headIterator.next = head;
            return headIterator;
        }
        method size () -> integer {
            return currentSize;
        }
        
        private method onDestroy() {
            while (size>0) {
                pop();
            }
        }
    }
//! endtextmacro


Which I also use in my unit-testing framework.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top