00001 /******************************************************************************* 00002 Copyright (c) 2011, Yahoo! Inc. 00003 All rights reserved. 00004 00005 Redistribution and use of this software in source and binary forms, 00006 with or without modification, are permitted provided that the following 00007 conditions are met: 00008 00009 * Redistributions of source code must retain the above 00010 copyright notice, this list of conditions and the 00011 following disclaimer. 00012 00013 * Redistributions in binary form must reproduce the above 00014 copyright notice, this list of conditions and the 00015 following disclaimer in the documentation and/or other 00016 materials provided with the distribution. 00017 00018 * Neither the name of Yahoo! Inc. nor the names of its 00019 contributors may be used to endorse or promote products 00020 derived from this software without specific prior 00021 written permission of Yahoo! Inc. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00024 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00025 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00026 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 00035 The Initial Developer of the Original Code is Shravan Narayanamurthy. 00036 ******************************************************************************/ 00037 /* 00038 * LDAUtil.h 00039 * 00040 * 00041 * 00042 * Created on: 20-Oct-2010 00043 * 00044 */ 00045 00046 #ifndef LDAUTIL_H_ 00047 #define LDAUTIL_H_ 00048 00049 #include <vector> 00050 #include <string> 00051 #include <sstream> 00052 00053 namespace LDAUtil { 00054 using namespace std; 00055 00056 /** 00057 * Utility class for tokenization and such other 00058 * commonly used functions 00059 */ 00060 class StringTokenizer { 00061 public: 00062 static void tokenize(const string& s, char delim, vector<string>& ret_vec); 00063 00064 private: 00065 StringTokenizer(); 00066 virtual ~StringTokenizer(); 00067 }; 00068 00069 class StringTrimmer { 00070 public: 00071 static void trim(string& s, char trim_char = ' '); 00072 private: 00073 StringTrimmer(); 00074 virtual ~StringTrimmer(); 00075 }; 00076 00077 class Itoa { 00078 public: 00079 static string get_string(const int i); 00080 private: 00081 static string _cache[100]; 00082 static stringstream _ss; 00083 00084 Itoa(); 00085 virtual ~Itoa(); 00086 }; 00087 00088 class DM_Server_Names { 00089 public: 00090 static string get_servant_name(const int server_id); 00091 static string get_server_endpoint(const string& host_port); 00092 00093 private: 00094 DM_Server_Names(); 00095 virtual ~DM_Server_Names(); 00096 }; 00097 } 00098 00099 #endif /* LDAUTIL_H_ */