For example if you want to format
void foo() {
int blah;
int foo;
int bar;
}
Navigate the the first '{' and press '=%' = will tell it format, where '%' will tell it to go to the corresponding block.
Topics for professional software engineers
void foo() {
int blah;
int foo;
int bar;
}
<?php
if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
This is a command line PHP script with one option.
Usage:
<?php echo $argv[0]; ?> <option>
<option> can be some word you would like
to print out. With the --help, -help, -h,
or -? options, you can get this help.
<?php
} else {
echo $argv[1];
}
?>
$client = new SOAPClient('http://webservices.daehosting.com/services/isbnservice.wso?WSDL');
$params = array('sISBN'=>"9781565926103");
$result = $client->IsValidISBN13($params);
function obj2array($obj) {
$out = array();
foreach ($obj as $key => $val) {
switch(true) {
case is_object($val):
$out[$key] = obj2array($val);
break;
case is_array($val):
$out[$key] = obj2array($val);
break;
default:
$out[$key] = $val;
}
}
return $out;
}
print_r(obj2array($result));
<?php
$client = new SOAPClient('http://webservices.daehosting.com/services/isbnservice.wso?WSDL');
$params = array('sISBN'=>"9781565926103");
$result = $client->IsValidISBN13($params);
function obj2array($obj) {
$out = array();
foreach ($obj as $key => $val) {
switch(true) {
case is_object($val):
$out[$key] = obj2array($val);
break;
case is_array($val):
$out[$key] = obj2array($val);
break;
default:
$out[$key] = $val;
}
}
return $out;
}
print_r(obj2array($result));
?>
struct AbstractClass {
virtual std::string speak() const = 0;
};
struct DerivedClassA : AbstractClass {
virtual std::string speak() const {return "Derived Class A";}
};
struct DerivedClassB : AbstractClass {
virtual std::string speak() const {return "Derived Class B";}
};
struct WrapperClass : AbstractClass , boost::python::wrapper<AbstractClass> {
virtual std::string speak() const {
return this->get_override("speak")();
}
};
BOOST_PYTHON_MODULE(PyHelloWorld)
{
using namespace boost::python;
def("getDerivedClassA",&getDerivedClassA,return_value_policy< manage_new_object >());
def("getDerivedClassB",&getDerivedClassB,return_value_policy< manage_new_object >());
class_<WrapperClass, boost::noncopyable > ("DerivedClass")
.def("speak",boost::python::pure_virtual(&AbstractClass::speak))
;
}
void start( ) {
using namespace boost::python;
Py_Initialize();
// Explicitly call the method that the BOOST_PYTHON_MODULE macro created.
// This sets up our DLL to be used by python.
initPyHelloWorld();
std::string pythonCommand;
try {
PyRun_SimpleString("import PyHelloWorld");
while(1) {
std::cout << ">>> ";
getline(std::cin,pythonCommand);
if (pythonCommand == "quit") {
break;
}else {
std::cout << PyRun_SimpleString(pythonCommand.c_str());
}
}
} catch ( error_already_set ) {
PyErr_Print();
}
Py_Finalize();
}
>>> import PyHelloWorld
0>>> a = PyHelloWorld.getDerivedClassA()
0>>> b = PyHelloWorld.getDerivedClassB()
0>>> print a.speak()
Derived Class A
0>>> print b.speak()
Derived Class B
0>>>
#define BOOST_ALL_NO_LIB
#include <boost/python.hpp>
char const* speak()
{
return "Hello World!";
}
BOOST_PYTHON_MODULE(PyHelloWorld)
{
using namespace boost::python;
def("speak", speak);
}
move PyHelloWorld.dll PyHelloWorld.pyd
c:\download\PyHelloWorld\PyHelloWorld\debug>c:\Python25\python.exe
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyHelloWorld
>>> print PyHelloWorld.speak();
Hello World!
>>>
// Noninstantiable utility class
public class UtilityClass {
// Suppress default constructor for noninstantiability
private UtilityClass() {
throw new AssertionError();
}
... // Remainder omitted
}
public class MyString {
private MyString() { }
private WeakHashMap<String,String> map = new WeakHashMap<String,String>();
public get(String s) {
if (map.get(s))
return map.get(s);
else {
map.put(s,s);
return map.get(s);
}
}
}
private static class IntegerCache {
private IntegerCache(){}
static final Integer cache[] = new Integer[-(-128) + 127 + 1];
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Integer(i - 128);
}
}
/**
* Returns a <tt>Integer</tt> instance representing the specified
* <tt>int</tt> value.
* If a new <tt>Integer</tt> instance is not required, this method
* should generally be used in preference to the constructor
* {@link #Integer(int)}, as this method is likely to yield
* significantly better space and time performance by caching
* frequently requested values.
*
* @param i an <code>int</code> value.
* @return a <tt>Integer</tt> instance representing <tt>i</tt>.
* @since 1.5
*/
public static Integer valueOf(int i) {
final int offset = 128;
if (i >= -128 && i <= 127) { // must cache
return IntegerCache.cache[i + offset];
}
return new Integer(i);
}
void swap(int &a, int &b) {
int temp = a ;
a = b;
b = temp;
}
int partition(int * arr,int left, int right, int pivotIndex) {
int pivotValue = arr[pivotIndex];
swap(arr[right],arr[pivotIndex]);
int storeIndex = left;
for (int i=left;i<right -1; ++i) {
if (arr[i] < pivotValue) {
swap(arr[i],arr[storeIndex]);
storeIndex++;
}
}
swap(arr[storeIndex],arr[right]);
return storeIndex;
}
void quicksort(int * arr, int left , int right) {
if (right > left) {
int pivotIndex = left;
int pivotNewIndex = partition(arr,left,right,pivotIndex);
quicksort(arr,left,pivotNewIndex-1);
quicksort(arr,pivotNewIndex+1,right);
}
}
int main(int argc, char** argv) {
int arr[10] = { 3, 6, 1, 5, 3, 2, 6, 8, 9, 6};
quicksort(&arr[0],0,9);
for(int i = 0 ; i < 10; ++i) {
printf("%d" , arr[i]);
}
}