forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Forest.cpp
Go to the documentation of this file.
1 
9 #include "Forest.h"
10 
11 namespace forest {
12 
22 bool Forest::readForestAdr(istream& in, fAdr_t& fa) {
23  int b1, b2;
24 
25  if (!Util::readInt(in,b1)) return false;
26  if (b1 < 0) { fa = b1; return true; }
27  if (!Util::verify(in,'.') || !Util::readInt(in,b2))
28  return false;
29  if (b1 == 0 && b2 != 0) return false;
30  if (b1 > 0xffff || b2 > 0xffff) return false;
31  fa = Forest::forestAdr(b1,b2);
32  return true;
33 }
34 
35 string Forest::nodeType2string(ntyp_t nt) {
36  string s;
37  if (nt == CLIENT) s = "client";
38  else if (nt == SERVER) s = "server";
39  else if (nt == ROUTER) s = "router";
40  else if (nt == CONTROLLER) s = "controller";
41  else s = "unknown node type";
42  return s;
43 }
44 
45 Forest::ntyp_t Forest::getNodeType(string& s) {
46  if (s.compare("client") == 0) return CLIENT;
47  if (s.compare("server") == 0) return SERVER;
48  if (s.compare("router") == 0) return ROUTER;
49  if (s.compare("controller") == 0) return CONTROLLER;
50  return UNDEF_NODE;
51 }
52 
53 
54 } // ends namespace
55