AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=58)
-   -   Methodmap Circular Dependency (https://forums.alliedmods.net/showthread.php?t=305749)

clug 03-03-2018 06:21

Methodmap Circular Dependency
 
Hi guys,
I've been working on an include for some custom data structures I need that other extensions/includes don't seem to solve. However, I've hit a roadblock, as I have two methodmaps that depend on each other, and I can't seem to find a way to prototype them as I would in any other language to make it work.

Here's a slimmed down example of what I'm trying to achieve:
PHP Code:

methodmap _Array {
    public 
_Object Get_Object() { /* code here */ };
    public 
bool Set_Object(_Object value) { /* code here */ };
}

methodmap _Object {
    public 
_Array Get_Array() { /* code here */ };
    public 
bool Set_Array(_Array value) { /* code here */ };


Obviously by default it won't work, but does prototyping exist for methodmaps in Pawn? I attempted putting this at the top of the include:
PHP Code:

methodmap _Object { }
methodmap _Array { } 

So that they are visible to one another, but this just results in an error:
Code:

error 110: _Array has already been defined (previously seen as methodmap)
Any ideas?
Thanks!

klippy 03-03-2018 07:00

Re: Methodmap Circular Dependency
 
https://github.com/alliedmodders/sourcepawn/pull/65
It's in the works but no there haven't been any updates for a long time.

clug 03-04-2018 01:53

Re: Methodmap Circular Dependency
 
Thanks for that, I ended up merging them into one methodmap with a boolean to denote which it should represent.

Peace-Maker 03-05-2018 05:19

Re: Methodmap Circular Dependency
 
You can "forward-declare" the tag using
Code:

enum _Object {};
before the _Array methodmap definition. You'll only be able to use the literal tag though, not any of the methods you declare later for the _Object tag.

Neuro Toxin 03-05-2018 15:52

Re: Methodmap Circular Dependency
 
Using Dynamic, the best I can achieve is declaring the circular reference members as Dynamic and using view_as<>().

http://console.aus-tg.com/index.php?...tedynamicclass

clug 09-24-2019 13:07

Re: Methodmap Circular Dependency
 
Quote:

Originally Posted by Peace-Maker (Post 2581431)
You can "forward-declare" the tag using
Code:

enum _Object {};
before the _Array methodmap definition. You'll only be able to use the literal tag though, not any of the methods you declare later for the _Object tag.

I appear to have arrived at this topic once again (by forgetting I had even asked this question and finding it on Google!). This suggestion has worked for me, except in my _Array methodmap I get a tag mismatch warning when attempting to return from a function which is typehinted to return _Object. I've tried all my usual tricks of putting it into a variable of the same type and typecasting it to no avail.

For example:

PHP Code:

enum _Object { }

methodmap _Array {
    public 
_Object GetObject(int index) {
        
_Object result view_as<_Object>(this.GetHandle(index));
        return 
result;  // <-- warning 213: tag mismatch
    
}


Am I chasing the impossible by trying to get this to compile without errors? I do have workarounds, as both _Array and _Object inherit from _Base, so I can simply make this return _Base and typecast it once outside the methodmap, but this doesn't feel clean compared to the theoretical alternative.

Thanks again.

Neuro Toxin 09-24-2019 16:20

Re: Methodmap Circular Dependency
 
If it's a tag mismatch it would still compile and work as expected wouldnt it?

clug 09-24-2019 20:11

Re: Methodmap Circular Dependency
 
Quote:

Originally Posted by Neuro Toxin (Post 2668028)
If it's a tag mismatch it would still compile and work as expected wouldnt it?

You are correct, I meant to say compile without warnings sorry. For CI purposes I like clean compiles with no warnings or errors.


All times are GMT -4. The time now is 00:48.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.