SNMPpp  v0.0.3-20-7eeb228
Classes, methods, and functions to use net-snmp from C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OID.hpp
Go to the documentation of this file.
1 // SNMPpp: https://sourceforge.net/p/snmppp/
2 // SNMPpp project uses the MIT license. See LICENSE for details.
3 // Copyright (C) 2013 Stephane Charette <stephanecharette@gmail.com>
4 
5 #pragma once
6 
7 #include <map>
8 #include <set>
9 #include <vector>
10 #include <string>
11 #include <ostream>
12 #include <SNMPpp/net-snmppp.hpp>
13 
14 
15 namespace SNMPpp
16 {
26  class OID
27  {
28  public:
29 
31  enum ECommon
32  {
33  // several common locations useful as a starting point
34  kInvalid = 0,
35  kEmpty = 1,
36  kInternet = 2,
38  kSysUpTime = 4,
39  kTrap = 5
40  };
41 
53  {
54  kUnknown = 0,
55  kLeafOnly = 1,
56  kPartial = 2,
57  kInverted = 3,
58  kFull = 4
59  };
60 
62  virtual ~OID( void );
63 
70  OID( void );
71 
73  OID( const OID &oid );
74 
81  OID( const char * const s );
82 
84  OID( const std::string &s );
85 
92  OID( const SNMPpp::OID::ECommon &location );
93 
95  OID( const oid * o, const size_t len );
96 
104  explicit OID( const netsnmp_variable_list *vl );
105 
107  virtual operator std::string( void ) const;
108 
112  virtual std::string to_str( void ) const { return operator std::string(); }
113 
115  virtual operator const oid *( void ) const;
116 
118  virtual operator oid *( void );
119 
121  virtual operator const unsigned char *( void ) const { return (unsigned char *)operator const oid*(); }
122 
124  virtual operator const void *( void ) const { return (void*)operator const oid*(); }
125 
127  virtual OID &clear( void );
128 
130  virtual bool empty( void ) const { return v.empty(); }
131 
133  virtual operator bool( void ) const { return ! empty(); }
134 
139  virtual operator size_t( void ) const { return v.size(); }
140 
142  virtual size_t size( void ) const { return v.size(); }
143 
145  virtual size_t len( void ) const { return v.size(); }
146 
148  virtual bool operator< ( const SNMPpp::OID &rhs ) const { return v < rhs.v; }
149  virtual bool operator<=( const SNMPpp::OID &rhs ) const { return v <= rhs.v; }
150  virtual bool operator> ( const SNMPpp::OID &rhs ) const { return v > rhs.v; }
151  virtual bool operator>=( const SNMPpp::OID &rhs ) const { return v >= rhs.v; }
152  virtual bool operator==( const SNMPpp::OID &rhs ) const { return v == rhs.v; }
153  virtual bool operator!=( const SNMPpp::OID &rhs ) const { return v != rhs.v; }
155 
163  virtual OID operator+ ( const oid o ) const;
164 
172  virtual OID &operator+=( const oid o );
173 
181  virtual OID operator+ ( const std::string &s ) const;
182 
190  virtual OID &operator+=( const std::string &s );
191 
200  virtual oid operator[]( const size_t idx ) const;
201 
203  virtual OID &set( const OID &oid );
204 
206  virtual OID &set( const char * const s );
207 
209  virtual OID &set( const std::string &s );
210 
212  virtual OID &set( const SNMPpp::OID::ECommon &location );
213 
215  virtual OID &operator=( const std::string &s ) { return set( s ); }
216 
218  virtual OID &operator=( const char * const s ) { return set( s ); }
219 
231  virtual bool isChildOf( const SNMPpp::OID &rhs ) const;
232 
243  virtual bool isParentOf( const SNMPpp::OID &rhs ) const;
244 
259  virtual bool isImmediateChildOf ( const SNMPpp::OID &rhs ) const;
260 
275  virtual bool isImmediateParentOf( const SNMPpp::OID &rhs ) const;
276 
278  virtual OID parent( const size_t level=1 ) const;
279 
281  virtual std::string nameFromMib( const SNMPpp::OID::ENameLookup lookup=SNMPpp::OID::kFull ) const;
282 
292  virtual std::string mibModuleName( const bool exact=false ) const;
293 
303  virtual std::string mibModuleFile( const bool exact=false ) const;
304 
306  virtual const struct tree *getTree( const bool exact=false ) const;
307 
309  virtual const struct module *getModule( const bool exact=false ) const;
310 
311  protected:
312 
313  std::vector < oid > v;
314  };
315 
317  typedef std::set <OID> SetOID;
318 
320  typedef std::vector<OID> VecOID;
321 
323  typedef std::map < SNMPpp::OID, netsnmp_variable_list *> MapOidVarList;
324 };
325 
326 
328 std::ostream &operator<<( std::ostream &os, const SNMPpp::OID &o );