blob: 633d1cf0ab02b31546708321eab116cc2adf27ba [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)
Jeff Thompsone589c3f2013-10-12 17:30:50 -070029 break;
Jeff Thompsonc0573432013-09-19 17:41:36 -070030
31 oid_.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
32
33 pos++;
34 }
35}
36
Jeff Thompson6c729a22013-12-20 10:37:59 -080037string OID::toString() const
Jeff Thompsonc0573432013-09-19 17:41:36 -070038{
39 ostringstream convert;
40
Jeff Thompson6c729a22013-12-20 10:37:59 -080041 vector<int>::const_iterator it = oid_.begin();
Jeff Thompsonc0573432013-09-19 17:41:36 -070042 for(; it < oid_.end(); it++){
43 if(it != oid_.begin())
44 convert << ".";
45 convert << *it;
46 }
47
48 return convert.str();
49}
50
Jeff Thompson6c729a22013-12-20 10:37:59 -080051bool OID::equal(const OID& oid) const
Jeff Thompsonc0573432013-09-19 17:41:36 -070052{
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}