Browse Source

Added support for nested namespaces in Namespace.cs.

pull/1/head
triton 14 years ago
parent
commit
e7f337f99c
  1. 61
      src/Bridge/Namespace.cs

61
src/Bridge/Namespace.cs

@ -8,6 +8,15 @@ namespace Cxxi
/// </summary> /// </summary>
public class Namespace public class Namespace
{ {
public string Name { get; set; }
public Namespace Parent { get; set; }
public bool IsAnonymous { get; set; }
public List<Namespace> Namespaces;
public List<Enumeration> Enums;
public List<Function> Functions;
public List<Class> Classes;
public Namespace() public Namespace()
: this(null, String.Empty) : this(null, String.Empty)
{ {
@ -19,42 +28,53 @@ namespace Cxxi
Parent = parent; Parent = parent;
IsAnonymous = isAnonymous; IsAnonymous = isAnonymous;
Namespaces = new List<Namespace>();
Enums = new List<Enumeration>(); Enums = new List<Enumeration>();
Functions = new List<Function>(); Functions = new List<Function>();
Classes = new List<Class>(); Classes = new List<Class>();
} }
public Enumeration FindEnum(string Name) public Namespace FindNamespace(string name)
{ {
return FindEnumWithName(Name); return Namespaces.Find(e => e.Name.Equals(name));
} }
public Function FindFunction(string Name) public Enumeration FindEnum(string name)
{ {
return Functions.Find(e => e.Name.Equals(Name)); return Enums.Find(e => e.Name.Equals(name));
} }
public Class FindClass(string Name) public Function FindFunction(string name)
{ {
return Classes.Find(e => e.Name.Equals(Name)); return Functions.Find(e => e.Name.Equals(name));
} }
public T FindType<T>(string Name) where T : Declaration public Class FindClass(string name, bool create = false)
{ {
var type = FindEnumWithName(Name) Class @class = Classes.Find(e => e.Name.Equals(name));
?? FindFunction(Name) ?? (Declaration)FindClass(Name);
return type as T; if (@class == null && create)
{
@class = new Class();
@class.Name = name;
Classes.Add(@class);
}
return @class;
} }
public Enumeration FindEnumWithName(string Name) public T FindType<T>(string name) where T : Declaration
{ {
return Enums.Find(e => e.Name.Equals(Name)); var type = FindEnum(name)
?? FindFunction(name) ?? (Declaration)FindClass(name);
return type as T;
} }
public Enumeration FindEnumWithItem(string Name) public Enumeration FindEnumWithItem(string name)
{ {
return Enums.Find(e => e.ItemsByName.ContainsKey(Name)); return Enums.Find(e => e.ItemsByName.ContainsKey(name));
} }
public bool HasDeclarations public bool HasDeclarations
@ -62,7 +82,8 @@ namespace Cxxi
get get
{ {
Predicate<Declaration> pred = (t => !t.Ignore); Predicate<Declaration> pred = (t => !t.Ignore);
return Enums.Exists(pred) || HasFunctions || Classes.Exists(pred); return Enums.Exists(pred) || HasFunctions
|| Classes.Exists(pred) || Namespaces.Exists(n => n.HasDeclarations);
} }
} }
@ -71,16 +92,8 @@ namespace Cxxi
get get
{ {
Predicate<Declaration> pred = (t => !t.Ignore); Predicate<Declaration> pred = (t => !t.Ignore);
return Functions.Exists(pred); return Functions.Exists(pred) || Namespaces.Exists(n => n.HasFunctions);
} }
} }
public string Name { get; set; }
public Namespace Parent { get; set; }
public bool IsAnonymous { get; set; }
public List<Enumeration> Enums;
public List<Function> Functions;
public List<Class> Classes;
} }
} }
Loading…
Cancel
Save