STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
IntegerType.cs
Go to the documentation of this file.
1 /*
2  * Created by SharpDevelop.
3  * User: lextm
4  * Date: 2008/7/25
5  * Time: 20:41
6  *
7  * To change this template use Tools | Options | Coding | Edit Standard Headers.
8  */
9 
10 using System;
11 using System.Collections.Generic;
12 
13 namespace Lextm.SharpSnmpLib.Mib.Elements.Types
14 {
19 
25  public sealed class IntegerType : BaseType
26  {
27  public enum Types
28  {
29  Integer,
30  Integer32
31  }
32 
33  private Types _type;
34  private bool _isEnumeration;
35  private ValueMap _map;
36  private ValueRanges _ranges;
37 
44  public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
45  : base (module, name)
46  {
47  Types? t = GetExactType(type);
48  type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
49  _type = t.Value;
50 
51  _isEnumeration = false;
52 
53  Symbol current = symbols.NextNonEOLSymbol();
54  if (current == Symbol.OpenBracket)
55  {
56  _isEnumeration = true;
57  symbols.PutBack(current);
58  _map = Lexer.DecodeEnumerations(symbols);
59  }
60  else if (current == Symbol.OpenParentheses)
61  {
62  symbols.PutBack(current);
63  _ranges = Lexer.DecodeRanges(symbols);
64  current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!");
65  }
66  else
67  {
68  symbols.PutBack(current);
69  }
70  }
71 
72  public Types Type
73  {
74  get { return _type; }
75  }
76 
77  public ValueRanges Ranges
78  {
79  get { return _ranges; }
80  }
81 
82  public bool IsEnumeration
83  {
84  get
85  {
86  return _isEnumeration;
87  }
88  }
89 
90  public ValueMap Enumeration
91  {
92  get { return _isEnumeration ? _map : null; }
93  }
94 
95  internal static Types? GetExactType(Symbol symbol)
96  {
97  if (symbol == Symbol.Integer)
98  {
99  // represents the ASN.1 builtin INTEGER type:
100  // may be represent any arbitrary (signed/unsigned) integer (in theory may have any size)
101  return Types.Integer;
102  }
103  else if (symbol == Symbol.Integer32)
104  {
105  // Integer32 ::= INTEGER (-2147483648..2147483647) // from SNMPv2-SMI
106  return Types.Integer32;
107  }
108 
109  return null;
110  }
111 
112  internal static bool IsIntegerType(Symbol symbol)
113  {
114  return GetExactType(symbol).HasValue;
115  }
116  }
117 }
MIB Module interface.
Definition: IModule.cs:36
static ValueRanges DecodeRanges(ISymbolEnumerator symbols)
Definition: Lexer.cs:409
IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
Creates an IntegerType instance.
Definition: IntegerType.cs:44
static readonly Symbol Integer
Definition: Symbol.cs:228
static ValueMap DecodeEnumerations(ISymbolEnumerator symbols)
Definition: Lexer.cs:534
The INTEGER type represents a list of alternatives, or a range of numbers.. Includes Integer32 as it'...
Definition: IntegerType.cs:25
static readonly Symbol OpenParentheses
Definition: Symbol.cs:211
static readonly Symbol OpenBracket
Definition: Symbol.cs:185
Lexer class that parses MIB files into symbol list.
Definition: Lexer.cs:21
static readonly Symbol Integer32
Definition: Symbol.cs:229
Description of Symbol.
Definition: Symbol.cs:20