blob: 2f4b2cf0a826bfc12a5837f7eb3190c8f7b66476 [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#ifndef CHRONOS_PROFILE_HPP
12#define CHRONOS_PROFILE_HPP
13
14#include "common.hpp"
15
16#include <ndn-cxx/security/identity-certificate.hpp>
17#include "profile.pb.h"
18
19namespace chronos {
20
21class Profile
22{
23public:
24 typedef std::map<std::string, std::string>::iterator iterator;
25 typedef std::map<std::string, std::string>::const_iterator const_iterator;
26
27 Profile()
28 {
29 }
30
31 Profile(const ndn::IdentityCertificate& identityCertificate);
32
33 Profile(const Name& identityName);
34
35 Profile(const Name& identityName,
36 const std::string& name,
37 const std::string& institution);
38
39 Profile(const Profile& profile);
40
41 ~Profile()
42 {
43 }
44
45 std::string&
46 operator[](const std::string& profileKey)
47 {
48 return m_entries[profileKey];
49 }
50
51 std::string
52 get(const std::string& profileKey) const
53 {
54 std::map<std::string, std::string>::const_iterator it = m_entries.find(profileKey);
55 if (it != m_entries.end())
56 return it->second;
57 else
58 return std::string();
59 }
60
61 Profile::iterator
62 begin()
63 {
64 return m_entries.begin();
65 }
66
67 Profile::const_iterator
68 begin() const
69 {
70 return m_entries.begin();
71 }
72
73 Profile::iterator
74 end()
75 {
76 return m_entries.end();
77 }
78
79 Profile::const_iterator
80 end() const
81 {
82 return m_entries.end();
83 }
84
85 void
86 encode(std::ostream& os) const;
87
88 void
89 decode(std::istream& is);
90
91 Name
92 getIdentityName() const
93 {
94 return ndn::Name(m_entries.at("IDENTITY"));
95 }
96
97 bool
98 operator==(const Profile& profile) const;
99
100 bool
101 operator!=(const Profile& profile) const;
102
103private:
104 static const std::string OID_NAME;
105 static const std::string OID_ORG;
106 static const std::string OID_GROUP;
107 static const std::string OID_HOMEPAGE;
108 static const std::string OID_ADVISOR;
109 static const std::string OID_EMAIL;
110
111 std::map<std::string, std::string> m_entries;
112};
113
114Chronos::ProfileMsg&
115operator<<(Chronos::ProfileMsg& msg, const Profile& profile);
116
117Chronos::ProfileMsg&
118operator>>(Chronos::ProfileMsg& msg, Profile& profile);
119
120} // namespace chronos
121
122#endif // CHRONOS_PROFILE_HPP