Closed AndyHolt closed 11 years ago
devicekind is an enumerated type defined in network.h and therefore each integer corresponds to a different device.
On 29 May 2013 21:31, adh635 notifications@github.com wrote:
I'm really confused as to what's happening with devkind function.
I was expecting to look up a device by its id and get a string back with the type of device (nand, or, clock, dtype etc).
Instead (see running of latest commit, line 243 of gui.cc), I get an integer.
Additionally, the device type is the same for all the devices we list, and only unique for what I assume are the type definitions that are printed out first.
Can anyone explain what's going on?
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14 .
That's expected behaviour, look in network.h and you'll find the devicekind enum. You may need to include network.h, but then you can compare the integer against (say) "orgate". The reason it's unique only for the first ones is that all of the devices are named early on in the definition file so they're at the beginning of the nametable.
On 29 May 2013 21:31, adh635 notifications@github.com wrote:
I'm really confused as to what's happening with devkind function.
I was expecting to look up a device by its id and get a string back with the type of device (nand, or, clock, dtype etc).
Instead (see running of latest commit, line 243 of gui.cc), I get an integer.
Additionally, the device type is the same for all the devices we list, and only unique for what I assume are the type definitions that are printed out first.
Can anyone explain what's going on?
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14 .
so to find out if a given device (by it's id) is a switch, I could write:
if(dmz->devkind(id) == "switch")
its a switch
else
its something else
almost, you should do if(dmz->devkind(id) == aswitch)
because it's an enum, not a string
On 29 May 2013 21:47, adh635 notifications@github.com wrote:
so to find out if a given device (by it's id) is a switch, I could write:
if(dmz->devkind(id) == "switch") its a switchelse its something else
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14#issuecomment-18645037 .
also the names are a bit weird:
typedef enum {aswitch, aclock, andgate, nandgate, orgate, norgate, xorgate, dtype, baddevice} devicekind;
On 29 May 2013 21:48, James Glanville james.n.glanville@gmail.com wrote:
almost, you should do if(dmz->devkind(id) == aswitch)
because it's an enum, not a string
On 29 May 2013 21:47, adh635 notifications@github.com wrote:
so to find out if a given device (by it's id) is a switch, I could write:
if(dmz->devkind(id) == "switch") its a switchelse its something else
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14#issuecomment-18645037 .
Use aswitch (no quotes) instead of "switch", as that's how it's defined. You don't need quotes as you're comparing ints.
On 29 May 2013 21:47, adh635 notifications@github.com wrote:
so to find out if a given device (by it's id) is a switch, I could write:
if(dmz->devkind(id) == "switch") its a switchelse its something else
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14#issuecomment-18645037 .
Ok, understand a bit better now, but still not getting the behaviour I think you guys are suggesting.
Running logsim on testgates.def gives only switch
as being a switch, not a
, b
, c
and d
.
Is this what you guys were expecting, and if so how could I generate a list of the defined switches? If not, any ideas what's going wrong?
Sorry if I'm being particularly dense in this.
No you're not being wrong, something is odd here. Did you try using parser::getswitch() btw?
On 29 May 2013 22:00, adh635 notifications@github.com wrote:
Ok, understand a bit better now, but still not getting the behaviour I think you guys are suggesting.
Running logsim on testgates.def gives only switch as being a switch, not a, b, c and d.
Is this what you guys were expecting, and if so how could I generate a list of the defined switches? If not, any ideas what's going wrong?
Sorry if I'm being particularly dense in this.
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14#issuecomment-18645818 .
Haven't tried this: parser isn't included in the includes for gui, I could do it but it feels like a bit of a cheat. Also, even if I did, how would I get the swnum
list required?
oh you can just iterate through getswitch(i) for i=0 -> nametable length (there's a method i wrote to give you that length, near the bottom of names.cc) it returns the name of switches as a string, or blank if it not a string, so you can iterate through, then use names->lookup to find the ids of any names that aren't ""
On 29 May 2013 23:42, adh635 notifications@github.com wrote:
Haven't tried this: parser isn't included in the includes for gui, I could do it but it feels like a bit of a cheat. Also, even if I did, how would I get the swnum list required?
— Reply to this email directly or view it on GitHubhttps://github.com/JamesGlanville/GF2/issues/14#issuecomment-18651091 .
now using devices.getswitch(int)
function
I'm really confused as to what's happening with
devkind
function.I was expecting to look up a device by its id and get a string back with the type of device (nand, or, clock, dtype etc).
Instead (see running of latest commit, line 243 of gui.cc), I get an integer.
Additionally, the device type is the same for all the devices we list, and only unique for what I assume are the type definitions that are printed out first.
Can anyone explain what's going on?