blob: 236e4208a3d0df13227133d762863565e0d88c86 [file] [log] [blame]
Jeff Thompsonc0573432013-09-19 17:41:36 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#include <stdlib.h>
9#include <sstream>
10
Jeff Thompson31b5c2f2013-10-12 15:13:16 -070011#include <ndn-cpp/encoding/oid.hpp>
Jeff Thompsonc0573432013-09-19 17:41:36 -070012
13using namespace std;
14
15namespace ndn {
16
17OID::OID(const string& oid)
18{
19 string str = oid + ".";
20
21 size_t pos = 0;
22 size_t ppos = 0;
23
24 while(string::npos != pos){
25 ppos = pos;
26
27 pos = str.find_first_of('.', pos);
28 if(pos == string::npos)
29 break;
30
31 oid_.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
32
33 pos++;
34 }
35}
36
37string OID::toString()
38{
39 ostringstream convert;
40
41 vector<int>::iterator it = oid_.begin();
42 for(; it < oid_.end(); it++){
43 if(it != oid_.begin())
44 convert << ".";
45 convert << *it;
46 }
47
48 return convert.str();
49}
50
51bool OID::equal(const OID& oid)
52{
53 vector<int>::const_iterator i = oid_.begin();
54 vector<int>::const_iterator j = oid.oid_.begin();
55
56 for (; i != oid_.end () && j != oid.oid_.end (); i++, j++) {
57 if(*i != *j)
58 return false;
59 }
60
61 if (i == oid_.end () && j == oid.oid_.end ())
62 return true;
63 else
64 return false;
65}
66
67}