That won't work properly either, forward declarations are not allowed in Thrift.
The reason for this is in the thread David referenced -- Thrift elements are
not nullable because in C++ we store actual objects rather than
references/pointers.
The simplest thing to do here is probably to simplify the Node object to just
reference domains by id. You probably don't need/want to always incur the full
overhead of storing a full list of rich Domain objects in every Node.
struct Domain {
5: Node node;
}
typedef list<i32> Domains; // Store a list of integer pointers to the Domains
by id
struct Node {
5: Domains domains;
}
-----Original Message-----
From: Rory McGuire [mailto:[email protected]]
Sent: Wednesday, January 13, 2010 12:43 AM
To: [email protected]
Subject: Re: Using a type before it has been defined
You could try this.
struct Node {}
struct Domain {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 state,
5: Node node,
}
typedef list<Domain> Domains
struct Node {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 running_state,
5: Domains domains,
}
typedef list<Node> Nodes
typedef i32 IdNum
service Virt {
Node getNode(1:i32 id),
IdNum saveNode(1:Node node),
Domain getDomain(1:i32 id),
Domains getDomainByNode(1:Node node),
Node getNodeOfDomain(1:i32 id),
Nodes getAllNodes(),
}
On 08 Jan 2010, at 8:28 AM, David Reiss wrote:
> Short answer: no. See this thread for details:
> http://markmail.org/thread/4pwhw5d254zrphv5
>
> Tim Hughes wrote:
>> I am wondering if the following concept is possible in some way,
>> other
>> than the way i am doing it obviously. It is a bit recursive and is
>> giving an issue when compiling. The error is:
>>
>> Type "Domains" has not been defined
>>
>>
>> and the thrift code is:
>>
>> struct Node {
>> 1: i32 id,
>> 2: string name,
>> 3: string hb_time,
>> 4: i32 running_state,
>> 5: Domains domains,
>> }
>>
>>
>> struct Domain {
>> 1: i32 id,
>> 2: string name,
>> 3: string hb_time,
>> 4: i32 state,
>> 5: Node node,
>> }
>>
>> typedef list<Domain> Domains
>> typedef list<Node> Nodes
>> typedef i32 IdNum
>>
>> service Virt {
>> Node getNode(1:i32 id),
>> IdNum saveNode(1:Node node),
>> Domain getDomain(1:i32 id),
>> Domains getDomainByNode(1:Node node),
>> Node getNodeOfDomain(1:i32 id),
>> Nodes getAllNodes(),
>> }
>>
>>
>>
>>
>> Tim Hughes
>> mailto:[email protected]