Esempio n. 1
0
int main( VecString args )
{
  bool showall = false;
  bool compact = false;
  //bool recovery = false;

  for( VecString::size_type n=1; n!=args.size(); n++ )
  {
    StringRef opt = args[n];
    if( opt == "-h" ) { usage(); return 0; }
    else if( opt == "-l" ) { showall = true; }
    else if( opt == "-c" ) { compact = true; }
    else if( opt == "-c" ) { compact = true; }
    else { usage(); throw std::runtime_error("unknown command line option "+opt); }
  }

  ListDevice devs = getDevices();

  if( showall == false )
    devs = getActiveDevices( devs );

  devs.sort();

  if( devs.empty() )
    { cout << "No devices found." << endl; return 2; }
  else if( compact )
    printDevices( devs );
  else
    prettyPrintDevices( devs );

  return 0;
}
Esempio n. 2
0
SInt64 RedisClient::keys( const std::string &pattern , VecString &values )
{
	BuildCommand cmd("KEYS");
	cmd << pattern;

	_getArry(cmd, values);
	return values.size();
}
Esempio n. 3
0
int getRefCount( const RegKey& dclass, const RegKey& key )
{
  int refcnt = 0;

  try
  {
    String symstr = key["Device Parameters"]("SymbolicName").data;
    VecString sym = split( "\\#", symstr );

    if( sym.size() >= 4 )
    {
      sym.erase( sym.begin(), sym.begin()+sym.size()-4 );
      String devstr = sym[3] +"\\##?#" + join("#",sym) + "\\Control";
      RegKey ctrl = dclass[devstr];
      refcnt = strtol( ctrl("ReferenceCount").data.c_str(), NULL, 0 );
    }
  }
  catch( std::runtime_error e ) { }

  return refcnt;
}
Esempio n. 4
0
bool RedisClient::eval( CResult& values , const string& script , const VecString& keysVec ,
		const VecString& argsVec )
{
	BuildCommand cmd("EVAL");
	string status;
	int len = keysVec.size();

	cmd << script << len;
	for ( int i = 0 ; i < len ; i++ )
	{
		cmd << keysVec[i];
	}

	len = argsVec.size();
	for ( int i = 0 ; i < len ; i++ )
	{
		cmd << argsVec[i];
	}

	return _getReply(values,cmd);
}
Esempio n. 5
0
bool RedisClient::sort( const string& key , VecString& values , const bool& desc )
{
	BuildCommand cmd("SORT");
	cmd << key;

	if ( desc )
		cmd << "DESC";

	if ( _getArry(cmd, values) )
	{
		return values.size();
	}
	return false;
}
 uint64_t CRedisClient::psubnumsub( CRedisClient::MapString& value, const VecString& channel )
 {
	Command cmd( "PUBSUB" );
	cmd << "NUMSUB";
	if ( channel.size() != 0 )
	{
		VecString::const_iterator it = channel.begin();
		for ( ; it != channel.end(); ++it )
		{
			cmd << *it ;
		}
	}

	return _getArry( cmd, value );
 }
Esempio n. 7
0
/**
 * [FuzzyFilter::find find the strings that match the source string in the target]
 * @param  source  [str1]
 * @param  targets [target strings]
 * @param  f       [function that filter the strings, such as to_lower_case()]
 * @return         [vector of matched strings]
 */
FuzzyFilter::VecString FuzzyFilter::find( const String &source,
                                          const VecString &targets,
                                          String (*f)(const String &)
                                        ) const
{
	VecString matches;

	for(int i=0; i<targets.size(); i++)
	{
		if(match(f(source), f(targets[i])))
			matches.push_back(targets[i]);
	}

	return matches;
}
 uint64_t CRedisClient::psubchannels( VecString& value, const VecString& pattern )
 {
	Command cmd( "PUBSUB" );
	cmd << "CHANNELS";

	if ( pattern.size() != 0 )
	{
		VecString::const_iterator it = pattern.begin();
		for ( ; it != pattern.end(); ++it )
		{
			cmd << *it ;
		}
	}

	return _getArry( cmd, value );
 }
Esempio n. 9
0
 void CRedisClient::punsubscribe( CResult& result, const VecString& pattern )
 {
	_socket.clearBuffer();

	Command cmd( "PUNSUBSCRIBE" );
	if ( pattern.size() != 0 )
	{
		VecString::const_iterator it = pattern.begin();
		for ( ; it != pattern.end(); ++it )
		{
			cmd << *it ;
		}
	}
	_sendCommand( cmd );

    _getReply( result );
 }
Esempio n. 10
0
 void CRedisClient::unsubscribe( CResult& result, const VecString& channel )
 {
	_socket.clearBuffer();

	Command cmd( "UNSUBSCRIBE" );
	if ( channel.size() != 0 )
	{
		VecString::const_iterator it = channel.begin();
		for ( ; it != channel.end(); ++it )
		{
			cmd << *it ;
		}
	}
	_sendCommand( cmd );

    _getResult( cmd, result );
 }
Esempio n. 11
0
/**
 * [FuzzyFilter::rank_find rank the result of the FuzzyFilter::find using edit distance]
 * @param  source  [str1]
 * @param  targets [target strings]
 * @param  f       [function that filter the strings, such as to_lower_case()]
 * @return         [vector of matched strings sorted by edit distance]
 */
FuzzyFilter::VecRankResult FuzzyFilter::rank_find( const String &source,
                                                   const VecString &targets,
                                                   String (*f)(const String &)
                                                 ) const
{
	VecRankResult results;

	VecString matches = find(source, targets, f);

	for(int i=0; i<matches.size(); i++)
	{
		int disance = edit_distance(f(source), f(matches[i]));

		results.push_back(RankResult(matches[i], disance));
	}

	std::sort(results.begin(), results.end());

	return results;
}
Esempio n. 12
0
bool DatasetCommand::run()
{
	VecString vecXlsxDir;
	Utility_split(m_strFromDir.c_str(), ",", vecXlsxDir);
	
	// 获取所有需要导出的Xlsx
	VecString files;
	for(auto i = 0; i < vecXlsxDir.size(); i++)
	{
		Utility_Find(vecXlsxDir[i].c_str(), files, true, "*.xlsx");
	}


	for(auto i = 0; i < files.size(); i++)
	{
		ParseXlsx(files[i].c_str());
	}

	
		// 导出代码
		if(m_strCodeDir.size() > 0)
		{
			CreatDir((char*)m_strCodeDir.c_str());

			std::string strDBDefine;

			strDBDefine = ""
				"#ifndef _DBDefine_Automake_H_\r\n"
				"#define _DBDefine_Automake_H_\r\n";

			strDBDefine += "\r\nstruct IDBBlock{};\r\n";

			strDBDefine += "enum TableType\r\n{\r\n";
			for(auto itrProps = m_mapTable.begin(); itrProps != m_mapTable.end(); ++itrProps)
			{
				auto vecPropertys = itrProps->second;
				if(vecPropertys.size() == 0)
					continue;

				strDBDefine += "\tTT_";
				std::string strName = itrProps->first;
				strDBDefine += strupr((char*)strName.c_str());
				strDBDefine += ",\r\n";
			}

			strDBDefine += "\tTT_Amount";
			strDBDefine += "\r\n};\r\n\r\n";

			
			for(auto itrProps = m_mapTableEnum.begin(); itrProps != m_mapTableEnum.end(); ++itrProps)
			{
				auto vecPropertys = itrProps->second;
				if(vecPropertys.size() == 0)
					continue;
				std::string strTableName = itrProps->first.c_str();
				strupr((char*)strTableName.c_str());
				std::string strEnumName = "EDT_";
				strEnumName+=strTableName;

				strDBDefine += "enum EDT_";
				strDBDefine += strTableName;
				strDBDefine += "\r\n{\r\n";
				
				for(auto i = 0; i < vecPropertys.size(); i++)
				{
					auto &enumData = vecPropertys[i];
					strDBDefine += "\tEDT_";
					strDBDefine += strTableName;
					strDBDefine += "_";
					strDBDefine += strupr((char*)enumData.strName.c_str());
					strDBDefine += "\t = \t";
					strDBDefine += strupr((char*)enumData.strType.c_str());
					strDBDefine += ", //";
					strDBDefine += strupr((char*)enumData.strDesc.c_str());
					strDBDefine += "\r\n";
				}
				strDBDefine += "};\r\n\r\n";
			}

			for(auto itrProps = m_mapTable.begin(); itrProps != m_mapTable.end(); ++itrProps)
			{
				auto vecPropertys = itrProps->second;
				if(vecPropertys.size() == 0)
					continue;

				strDBDefine += "struct DBData_";
				strDBDefine += itrProps->first;
				strDBDefine += " : IDBBlock";
				
				strDBDefine += "\r\n{\r\n";
				
				for(auto i = 0; i < vecPropertys.size(); i++)
				{
					strDBDefine += "\t";					
					if(vecPropertys[i].strType == "string")
					{
						strDBDefine += "const char*";		
					}
					else
					{
						strDBDefine += vecPropertys[i].strType;					
					}
					strDBDefine += " ";
					strDBDefine += vecPropertys[i].strName;
					strDBDefine += ";//";
					strDBDefine += vecPropertys[i].strDesc;		
					if(i+1 != vecPropertys.size())
						strDBDefine += "\r\n";
				}
				
				strDBDefine += "\r\n};\r\n\r\n";

			}


			strDBDefine += ""
				"#endif";

			Utility_ConvertUtf8ToGBK(strDBDefine);
			FILE *fp = fopen((m_strCodeDir+"DBDefine.h").c_str(), "wb");

			fwrite(strDBDefine.c_str(), strDBDefine.size(), 1, fp);

			fclose(fp);
		}
		
		// 导出csv的表名数据
		if(m_strCSVDir.size() > 0)
		{
			FILE *fp = fopen((m_strCSVDir+"_index").c_str(), "wb");

			int nCount = m_mapTable.size();
			fwrite(&nCount, sizeof(nCount), 1, fp);
			
			for(auto itrProps = m_mapTable.begin(); itrProps != m_mapTable.end(); ++itrProps)
			{
				char cLength = itrProps->first.size();
				fwrite(&cLength, sizeof(cLength), 1, fp);
				fwrite(itrProps->first.c_str(), cLength, 1, fp);
			}

			fclose(fp);
		}

	return true;
}