예제 #1
0
/* 
INPUT:  Single line '\n' terminated.  	
	Login:mtenniswood;Password:Tobart;Device name:motorola XT1565;\n
	
OUTPUT: 
	m_login_name
	m_login_password
*/
bool ServerHandler::parse_credentials( string mCredentials )
{
	bool retval = true;
	SuperString str = mCredentials;
	
	int count = str.split(';');
	str.trim_spaces_in_splits();		
	if (count < 3) {
		form_response( "Sorry there was garbled text in your credentials." );
		return false;		
	}
	//	[0] is "Login;"
	SuperString name   = str.m_split_words[1];	// UserID
	SuperString passwd = str.m_split_words[2];	// Password
	SuperString hostname = str.m_split_words[3];	// Password
		
	name.split(':');
	m_login_name = name.m_split_words[1];
	passwd.split(':'); 
	m_login_password = passwd.m_split_words[1];
			
	hostname.split(':');
	m_login_hostname = hostname.m_split_words[1];
	//printf("\tdevname=%s\n", m_login_hostname.c_str() );
	//printf("Login=%s\t\tpasswd=%s\n", m_login_name.c_str(), m_login_password.c_str() );
	return retval;
}
예제 #2
0
void LitterNetwork::create(istream& in) {
  SuperString line;
  map<int, LitterNode*> name_map;
  while (getline(in, line, '\n')) {
    vector<SuperString> parts = line.split("\t");
    int a = atoi(parts[0].c_str());
    int b = atoi(parts[1].c_str());

    if (a == b) continue;

    LitterNode* nodea = name_map[a];
    LitterNode* nodeb = name_map[b];

    if (nodea == NULL) {
      nodea = new LitterNode(a);
      name_map[a] = nodea;
    }

    if (nodeb == NULL) {
      nodeb = new LitterNode(b);
      name_map[b] = nodeb;
    }

    if(add(Edge(nodea, nodeb))) {
      nodea->stats.degree++;
      nodeb->stats.degree++;
    }
  }

  auto_ptr<NodeIterator> ni(getNodeIterator());
  while (ni->moveNext()) {
    LitterNode* node = dynamic_cast<LitterNode*>(ni->current());
    node->setNeighborIT(getNeighborIterator(node));
  }
}
예제 #3
0
int MenuItem::file_results(Sentence& mSentence)
{
    SuperString tmp;
    //for (auto x:mSentence.m_reduced_sentence.regex_matches)
    for (int m=1; m<mSentence.m_reduced_sentence.regex_matches.size(); m++)
    {
        tmp = mSentence.m_reduced_sentence.regex_matches[m].str();
        
        if (mSentence.m_reduced_sentence.regex_matches.size())
            m_quantity = 1;
        // is first match a number?  file as Quantity
        tmp.trim_spaces();
        tmp.split(' ');
        if (tmp.is_nth_word_a_number(0))
        {
            m_quantity = stof( tmp.c_str() );
        }
        
        // is match a required option?
        if (m_required_options.size())
        {
            string exp;
            for (int ro=0; ro<m_required_options.size(); ro++)
            {
                exp += m_required_options[ro].name;
                tmp.regex_find( exp );
                size_t result = tmp.regex_matches.size();           // Select the item, if info provided in sentence.
                if (result)                                         // (we'll not have to ask the user)
                    m_required_options[ro].selected_item = tmp.regex_matches[0];
            }
        }
        
        // Is the match an additional topping?
        for (int at=0; at<m_additional_toppings.size(); at++)
        {
            string str = m_additional_toppings[at].name.c_str();    //
            tmp.regex_find( str );
            if ( tmp.regex_matches.size() )
                m_additional_toppings[at].requested_indices.push_back( tmp.c_str() );
        }
        string tmps;
        // is match a removed topping?
        for (int st=0; st<m_standard_toppings.size(); st++)
        {
            string str = m_standard_toppings[st].name.c_str();    //
            tmp.regex_find( str );
            //tmps = tmp;
            if ( tmp.regex_matches.size() )
                m_standard_toppings[st].requested_indices.push_back( tmp );
        }
    }
    return m_quantity;
}
예제 #4
0
void Network::readFrom(istream& in) {

  SuperString line;
  map<string, Node*> name_map;
  while( getline(in, line, '\n') ) {
    if( line[0] == '#' ) { //This is a comment
      continue;
    }
    vector<SuperString> result = line.split(" : ");
    Node* first = 0;
    Node* second = 0;
    if( name_map.find(result[0]) == name_map.end() ) {
      //This is a new node:
      if( result[0] != "" ) {
        first = new Node(result[0]);
        name_map[ result[0] ] = first;
        add( first );
      }
    }
    else {
      first = name_map[ result[0] ];
    }
    if( result.size() == 1 ) { //There was no neighbors
      continue;
    }
    result = result[1].split(" ");
    vector<SuperString>::iterator sit;
    for(sit = result.begin();
	sit != result.end();
	sit++) {
      second = 0;
      if( name_map.find( *sit ) == name_map.end() ) {
        //This is a new node:
	if( *sit != "" ) {
          second = new Node( *sit );
          name_map[ *sit ] = second;
	  add( second );
	}
      }
      else {
        second = name_map[ *sit ];
      }
      //Add the edge:
      if( first && second ) {
        add( Edge(first, second) );
      }
    }
  }
	
}
예제 #5
0
Network* NetworkFactory::create(istream& in)
{
  Network* net = new Network();
  SuperString line;
  while( getline(in, line, '\n') ) {
    if( line[0] == '#' ) { //This is a comment
      continue;
    }
    vector<SuperString> result = line.split(" : ");
    Node* first = 0;
    Node* second = 0;
    first = _nf->create(result[0]);
    net->add( first ); 
    if( result.size() == 1 ) { //There were no neighbors
      continue;
    }
    //There is a list of second nodes:
    auto_ptr< Iterator<SuperString> > si( result[1].spliterator(" ") );
    while( si->moveNext() ) {
      second = 0;
      second = _nf->create( si->current() );
      net->add( second );
      Edge* e = 0;
      if( result.size() > 2 ) {
        e = _ef->create(first, second, result[2]);
      }
      else {
        e = _ef->create(first, second);
      }
      //Add the edge:
      if( e ) {
	/**
	 * Remember: we have to add references to edges, 
	 * not pointers.  This is because we don't want to allow
	 * multiple edges between nodes (for now).
	 */
        net->add( *e );
      }
      delete e;
    }
  }
  return net;
}
예제 #6
0
int main(int argc, char* argv[]) {

  vector<string> reqs;
  reqs.push_back("input");
  reqs.push_back("subgraph_nodes");
  reqs.push_back("out-prefix");
 
  vector<string> opts;
  opts.push_back("weighted");
  opts.push_back("first_is_name");
  OptionParser op(reqs,opts);
  try {
    op.parse(argc, argv);
  }
  catch (exception x) {
    cerr << "usage: " << argv[0] << op.getUsageString() << endl;
    return -1;
  }
  NetworkFactory* nf;
  NodeFactory* node_f = new NamedNodeFactory();
  bool weighted = op.getBoolOpt("weighted", false);
  if( weighted ) {
    nf = new WeightedNetworkFactory(node_f,
                                    new WeightedEdgeFactory());
  }
  else {
    //Here is unweighted:
    nf = new NetworkFactory(node_f,
                            new EdgeFactory());
  }
  Network* net;
  if( op.getStringOpt("input", "-") == "-" ) {
    net = nf->create(cin);
  }
  else {
    ifstream input( op.getStringOpt("input","").c_str() );
    net = nf->create(input);
  }
  //Subgraph
  ifstream sg( op.getStringOpt("subgraph_nodes","").c_str() );
  bool first_is_name = op.getBoolOpt("first_is_name", false);  

  SuperString line;
  int line_cnt = 0;
  while(getline(sg, line, '\n')) {
    if( line[0] == '#' ) { //This is a comment
      continue;
    }
    vector<SuperString> parts = line.split(" ");
    string name;
    int idx = 0;
    if( first_is_name ) {
      name = parts[0]; 
      idx = 1;
    }
    else {
      stringstream ss;
      ss << line_cnt;
      name = ss.str();
    }
    Network* sg_net;
    if( weighted ) { sg_net = new WeightedNetwork(); }
    else { sg_net = new Network(); }
    for(int i = idx; i < parts.size(); i++) {
      sg_net->add( node_f->create(parts[i]) );
    }
    sg_net->addJoiningEdgesFrom(net);
    ofstream out((op.getStringOpt("out-prefix","") + name).c_str());
    sg_net->printTo(out);
    delete sg_net; 
    line_cnt += 1;
  }
  
}
예제 #7
0
void Network::readFromGDL(std::istream& in){
  SuperString line;
  map<string, Node*> name_map;
  list<string> edge_src;
  list<string> edge_dst;
  int node=0, edge=0;
  Node* temp1 = 0;
  Node* temp2 = 0;

  while( getline(in, line, '\n') ) 
  {
    if( line[0] == '/' && line[1] == '/' ) continue;

    vector<SuperString> result = line.split(" ");
    vector<SuperString>::iterator sit;
    string nodename="", source="", target="";

    for (sit = result.begin(); sit != result.end(); sit++)
    {
      // note: should be able to handle node/edge definitions that span multiple lines now
      // note: doesn't handle multiword titles/sources/destinations, but they shouldn't exist anyway

      if (*sit == "node:")
        node = 1;
      else if (*sit == "edge:" || *sit == "nearedge:")
        edge = 1;
      else if (node == 1 && *sit == "title:")
      {
        sit++;
        nodename = *sit;

        if (name_map.find(nodename) == name_map.end()) // if new node...
        {
          temp1 = new Node(nodename);
          name_map[nodename] = temp1;
          add( temp1 );
          //cout<<"Created node "<<nodename<<endl;
        }

        nodename = "";
        node = 0;
      }
      else if (edge == 1 && (*sit == "targetname:" || *sit == "target:"))
      {
        sit++;
        target = *sit;
      }
      else if (edge == 1 && (*sit == "sourcename:" || *sit == "source:"))
      {
        sit++;
        source = *sit;
      }

      if (edge == 1 && source != "" && target != "")
      {
        edge_src.push_front(source);
        edge_dst.push_front(target);
        source = "";
        target = "";
        edge = 0;
      }

    }
  }

  list<string>::iterator i = edge_src.begin(), j = edge_dst.begin();

  while (i != edge_src.end())
  {
    //cout<<"Created edge from "<<*i<<" to "<<*j<<endl;
    temp1 = name_map[*i];
    temp2 = name_map[*j];
    add( Edge(temp1, temp2) );
    i++;
    j++;
  }

	
}