aboutsummaryrefslogtreecommitdiff
path: root/mp/src/thirdparty/protobuf-2.3.0/examples
diff options
context:
space:
mode:
authorNarendra Umate <[email protected]>2013-12-08 01:27:41 -0800
committerNarendra Umate <[email protected]>2013-12-08 01:27:41 -0800
commit4fa56874ba1557274c10077bf8386ece4c61dbd6 (patch)
treee2d336604e960b548e996d2e7dcfc5a1e1401b9e /mp/src/thirdparty/protobuf-2.3.0/examples
parentAdded DS_Store to .gitignore. (diff)
parentMake libSDL2.so/dylib into symlinks. (diff)
downloadsource-sdk-2013-4fa56874ba1557274c10077bf8386ece4c61dbd6.tar.xz
source-sdk-2013-4fa56874ba1557274c10077bf8386ece4c61dbd6.zip
Merge remote-tracking branch 'upstream/master'
Reverted .gitattributes xcode_ccache_wrapper change. Fixed line endings for .gitignore and .gitattributes.
Diffstat (limited to 'mp/src/thirdparty/protobuf-2.3.0/examples')
-rw-r--r--mp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java178
-rw-r--r--mp/src/thirdparty/protobuf-2.3.0/examples/ListPeople.java100
-rw-r--r--mp/src/thirdparty/protobuf-2.3.0/examples/README.txt58
-rw-r--r--mp/src/thirdparty/protobuf-2.3.0/examples/add_person.cc190
-rw-r--r--mp/src/thirdparty/protobuf-2.3.0/examples/addressbook.proto60
-rw-r--r--mp/src/thirdparty/protobuf-2.3.0/examples/list_people.cc136
6 files changed, 361 insertions, 361 deletions
diff --git a/mp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java b/mp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java
index 48045ec3..4917684b 100644
--- a/mp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java
+++ b/mp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java
@@ -1,89 +1,89 @@
-// See README.txt for information and build instructions.
-
-import com.example.tutorial.AddressBookProtos.AddressBook;
-import com.example.tutorial.AddressBookProtos.Person;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.io.PrintStream;
-
-class AddPerson {
- // This function fills in a Person message based on user input.
- static Person PromptForAddress(BufferedReader stdin,
- PrintStream stdout) throws IOException {
- Person.Builder person = Person.newBuilder();
-
- stdout.print("Enter person ID: ");
- person.setId(Integer.valueOf(stdin.readLine()));
-
- stdout.print("Enter name: ");
- person.setName(stdin.readLine());
-
- stdout.print("Enter email address (blank for none): ");
- String email = stdin.readLine();
- if (email.length() > 0) {
- person.setEmail(email);
- }
-
- while (true) {
- stdout.print("Enter a phone number (or leave blank to finish): ");
- String number = stdin.readLine();
- if (number.length() == 0) {
- break;
- }
-
- Person.PhoneNumber.Builder phoneNumber =
- Person.PhoneNumber.newBuilder().setNumber(number);
-
- stdout.print("Is this a mobile, home, or work phone? ");
- String type = stdin.readLine();
- if (type.equals("mobile")) {
- phoneNumber.setType(Person.PhoneType.MOBILE);
- } else if (type.equals("home")) {
- phoneNumber.setType(Person.PhoneType.HOME);
- } else if (type.equals("work")) {
- phoneNumber.setType(Person.PhoneType.WORK);
- } else {
- stdout.println("Unknown phone type. Using default.");
- }
-
- person.addPhone(phoneNumber);
- }
-
- return person.build();
- }
-
- // Main function: Reads the entire address book from a file,
- // adds one person based on user input, then writes it back out to the same
- // file.
- public static void main(String[] args) throws Exception {
- if (args.length != 1) {
- System.err.println("Usage: AddPerson ADDRESS_BOOK_FILE");
- System.exit(-1);
- }
-
- AddressBook.Builder addressBook = AddressBook.newBuilder();
-
- // Read the existing address book.
- try {
- FileInputStream input = new FileInputStream(args[0]);
- addressBook.mergeFrom(input);
- input.close();
- } catch (FileNotFoundException e) {
- System.out.println(args[0] + ": File not found. Creating a new file.");
- }
-
- // Add an address.
- addressBook.addPerson(
- PromptForAddress(new BufferedReader(new InputStreamReader(System.in)),
- System.out));
-
- // Write the new address book back to disk.
- FileOutputStream output = new FileOutputStream(args[0]);
- addressBook.build().writeTo(output);
- output.close();
- }
-}
+// See README.txt for information and build instructions.
+
+import com.example.tutorial.AddressBookProtos.AddressBook;
+import com.example.tutorial.AddressBookProtos.Person;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PrintStream;
+
+class AddPerson {
+ // This function fills in a Person message based on user input.
+ static Person PromptForAddress(BufferedReader stdin,
+ PrintStream stdout) throws IOException {
+ Person.Builder person = Person.newBuilder();
+
+ stdout.print("Enter person ID: ");
+ person.setId(Integer.valueOf(stdin.readLine()));
+
+ stdout.print("Enter name: ");
+ person.setName(stdin.readLine());
+
+ stdout.print("Enter email address (blank for none): ");
+ String email = stdin.readLine();
+ if (email.length() > 0) {
+ person.setEmail(email);
+ }
+
+ while (true) {
+ stdout.print("Enter a phone number (or leave blank to finish): ");
+ String number = stdin.readLine();
+ if (number.length() == 0) {
+ break;
+ }
+
+ Person.PhoneNumber.Builder phoneNumber =
+ Person.PhoneNumber.newBuilder().setNumber(number);
+
+ stdout.print("Is this a mobile, home, or work phone? ");
+ String type = stdin.readLine();
+ if (type.equals("mobile")) {
+ phoneNumber.setType(Person.PhoneType.MOBILE);
+ } else if (type.equals("home")) {
+ phoneNumber.setType(Person.PhoneType.HOME);
+ } else if (type.equals("work")) {
+ phoneNumber.setType(Person.PhoneType.WORK);
+ } else {
+ stdout.println("Unknown phone type. Using default.");
+ }
+
+ person.addPhone(phoneNumber);
+ }
+
+ return person.build();
+ }
+
+ // Main function: Reads the entire address book from a file,
+ // adds one person based on user input, then writes it back out to the same
+ // file.
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.err.println("Usage: AddPerson ADDRESS_BOOK_FILE");
+ System.exit(-1);
+ }
+
+ AddressBook.Builder addressBook = AddressBook.newBuilder();
+
+ // Read the existing address book.
+ try {
+ FileInputStream input = new FileInputStream(args[0]);
+ addressBook.mergeFrom(input);
+ input.close();
+ } catch (FileNotFoundException e) {
+ System.out.println(args[0] + ": File not found. Creating a new file.");
+ }
+
+ // Add an address.
+ addressBook.addPerson(
+ PromptForAddress(new BufferedReader(new InputStreamReader(System.in)),
+ System.out));
+
+ // Write the new address book back to disk.
+ FileOutputStream output = new FileOutputStream(args[0]);
+ addressBook.build().writeTo(output);
+ output.close();
+ }
+}
diff --git a/mp/src/thirdparty/protobuf-2.3.0/examples/ListPeople.java b/mp/src/thirdparty/protobuf-2.3.0/examples/ListPeople.java
index defb19c7..b2f153af 100644
--- a/mp/src/thirdparty/protobuf-2.3.0/examples/ListPeople.java
+++ b/mp/src/thirdparty/protobuf-2.3.0/examples/ListPeople.java
@@ -1,50 +1,50 @@
-// See README.txt for information and build instructions.
-
-import com.example.tutorial.AddressBookProtos.AddressBook;
-import com.example.tutorial.AddressBookProtos.Person;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-
-class ListPeople {
- // Iterates though all people in the AddressBook and prints info about them.
- static void Print(AddressBook addressBook) {
- for (Person person: addressBook.getPersonList()) {
- System.out.println("Person ID: " + person.getId());
- System.out.println(" Name: " + person.getName());
- if (person.hasEmail()) {
- System.out.println(" E-mail address: " + person.getEmail());
- }
-
- for (Person.PhoneNumber phoneNumber : person.getPhoneList()) {
- switch (phoneNumber.getType()) {
- case MOBILE:
- System.out.print(" Mobile phone #: ");
- break;
- case HOME:
- System.out.print(" Home phone #: ");
- break;
- case WORK:
- System.out.print(" Work phone #: ");
- break;
- }
- System.out.println(phoneNumber.getNumber());
- }
- }
- }
-
- // Main function: Reads the entire address book from a file and prints all
- // the information inside.
- public static void main(String[] args) throws Exception {
- if (args.length != 1) {
- System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
- System.exit(-1);
- }
-
- // Read the existing address book.
- AddressBook addressBook =
- AddressBook.parseFrom(new FileInputStream(args[0]));
-
- Print(addressBook);
- }
-}
+// See README.txt for information and build instructions.
+
+import com.example.tutorial.AddressBookProtos.AddressBook;
+import com.example.tutorial.AddressBookProtos.Person;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+class ListPeople {
+ // Iterates though all people in the AddressBook and prints info about them.
+ static void Print(AddressBook addressBook) {
+ for (Person person: addressBook.getPersonList()) {
+ System.out.println("Person ID: " + person.getId());
+ System.out.println(" Name: " + person.getName());
+ if (person.hasEmail()) {
+ System.out.println(" E-mail address: " + person.getEmail());
+ }
+
+ for (Person.PhoneNumber phoneNumber : person.getPhoneList()) {
+ switch (phoneNumber.getType()) {
+ case MOBILE:
+ System.out.print(" Mobile phone #: ");
+ break;
+ case HOME:
+ System.out.print(" Home phone #: ");
+ break;
+ case WORK:
+ System.out.print(" Work phone #: ");
+ break;
+ }
+ System.out.println(phoneNumber.getNumber());
+ }
+ }
+ }
+
+ // Main function: Reads the entire address book from a file and prints all
+ // the information inside.
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
+ System.exit(-1);
+ }
+
+ // Read the existing address book.
+ AddressBook addressBook =
+ AddressBook.parseFrom(new FileInputStream(args[0]));
+
+ Print(addressBook);
+ }
+}
diff --git a/mp/src/thirdparty/protobuf-2.3.0/examples/README.txt b/mp/src/thirdparty/protobuf-2.3.0/examples/README.txt
index 03caf876..d22bf06c 100644
--- a/mp/src/thirdparty/protobuf-2.3.0/examples/README.txt
+++ b/mp/src/thirdparty/protobuf-2.3.0/examples/README.txt
@@ -1,29 +1,29 @@
-This directory contains example code that uses Protocol Buffers to manage an
-address book. Two programs are provided, each with three different
-implementations, one written in each of C++, Java, and Python. The add_person
-example adds a new person to an address book, prompting the user to input
-the person's information. The list_people example lists people already in the
-address book. The examples use the exact same format in all three languages,
-so you can, for example, use add_person_java to create an address book and then
-use list_people_python to read it.
-
-You must install the protobuf package before you can build these.
-
-To build all the examples (on a unix-like system), simply run "make". This
-creates the following executable files in the current directory:
- add_person_cpp list_people_cpp
- add_person_java list_people_java
- add_person_python list_people_python
-
-If you only want to compile examples in one language, use "make cpp"*,
-"make java", or "make python".
-
-All of these programs simply take an address book file as their parameter.
-The add_person programs will create the file if it doesn't already exist.
-
-These examples are part of the Protocol Buffers tutorial, located at:
- http://code.google.com/apis/protocolbuffers/docs/tutorials.html
-
-* Note that on some platforms you may have to edit the Makefile and remove
-"-lpthread" from the linker commands (perhaps replacing it with something else).
-We didn't do this automatically because we wanted to keep the example simple.
+This directory contains example code that uses Protocol Buffers to manage an
+address book. Two programs are provided, each with three different
+implementations, one written in each of C++, Java, and Python. The add_person
+example adds a new person to an address book, prompting the user to input
+the person's information. The list_people example lists people already in the
+address book. The examples use the exact same format in all three languages,
+so you can, for example, use add_person_java to create an address book and then
+use list_people_python to read it.
+
+You must install the protobuf package before you can build these.
+
+To build all the examples (on a unix-like system), simply run "make". This
+creates the following executable files in the current directory:
+ add_person_cpp list_people_cpp
+ add_person_java list_people_java
+ add_person_python list_people_python
+
+If you only want to compile examples in one language, use "make cpp"*,
+"make java", or "make python".
+
+All of these programs simply take an address book file as their parameter.
+The add_person programs will create the file if it doesn't already exist.
+
+These examples are part of the Protocol Buffers tutorial, located at:
+ http://code.google.com/apis/protocolbuffers/docs/tutorials.html
+
+* Note that on some platforms you may have to edit the Makefile and remove
+"-lpthread" from the linker commands (perhaps replacing it with something else).
+We didn't do this automatically because we wanted to keep the example simple.
diff --git a/mp/src/thirdparty/protobuf-2.3.0/examples/add_person.cc b/mp/src/thirdparty/protobuf-2.3.0/examples/add_person.cc
index dc9dbf36..b9ca44fc 100644
--- a/mp/src/thirdparty/protobuf-2.3.0/examples/add_person.cc
+++ b/mp/src/thirdparty/protobuf-2.3.0/examples/add_person.cc
@@ -1,95 +1,95 @@
-// See README.txt for information and build instructions.
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include "addressbook.pb.h"
-using namespace std;
-
-// This function fills in a Person message based on user input.
-void PromptForAddress(tutorial::Person* person) {
- cout << "Enter person ID number: ";
- int id;
- cin >> id;
- person->set_id(id);
- cin.ignore(256, '\n');
-
- cout << "Enter name: ";
- getline(cin, *person->mutable_name());
-
- cout << "Enter email address (blank for none): ";
- string email;
- getline(cin, email);
- if (!email.empty()) {
- person->set_email(email);
- }
-
- while (true) {
- cout << "Enter a phone number (or leave blank to finish): ";
- string number;
- getline(cin, number);
- if (number.empty()) {
- break;
- }
-
- tutorial::Person::PhoneNumber* phone_number = person->add_phone();
- phone_number->set_number(number);
-
- cout << "Is this a mobile, home, or work phone? ";
- string type;
- getline(cin, type);
- if (type == "mobile") {
- phone_number->set_type(tutorial::Person::MOBILE);
- } else if (type == "home") {
- phone_number->set_type(tutorial::Person::HOME);
- } else if (type == "work") {
- phone_number->set_type(tutorial::Person::WORK);
- } else {
- cout << "Unknown phone type. Using default." << endl;
- }
- }
-}
-
-// Main function: Reads the entire address book from a file,
-// adds one person based on user input, then writes it back out to the same
-// file.
-int main(int argc, char* argv[]) {
- // Verify that the version of the library that we linked against is
- // compatible with the version of the headers we compiled against.
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- if (argc != 2) {
- cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
- return -1;
- }
-
- tutorial::AddressBook address_book;
-
- {
- // Read the existing address book.
- fstream input(argv[1], ios::in | ios::binary);
- if (!input) {
- cout << argv[1] << ": File not found. Creating a new file." << endl;
- } else if (!address_book.ParseFromIstream(&input)) {
- cerr << "Failed to parse address book." << endl;
- return -1;
- }
- }
-
- // Add an address.
- PromptForAddress(address_book.add_person());
-
- {
- // Write the new address book back to disk.
- fstream output(argv[1], ios::out | ios::trunc | ios::binary);
- if (!address_book.SerializeToOstream(&output)) {
- cerr << "Failed to write address book." << endl;
- return -1;
- }
- }
-
- // Optional: Delete all global objects allocated by libprotobuf.
- google::protobuf::ShutdownProtobufLibrary();
-
- return 0;
-}
+// See README.txt for information and build instructions.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "addressbook.pb.h"
+using namespace std;
+
+// This function fills in a Person message based on user input.
+void PromptForAddress(tutorial::Person* person) {
+ cout << "Enter person ID number: ";
+ int id;
+ cin >> id;
+ person->set_id(id);
+ cin.ignore(256, '\n');
+
+ cout << "Enter name: ";
+ getline(cin, *person->mutable_name());
+
+ cout << "Enter email address (blank for none): ";
+ string email;
+ getline(cin, email);
+ if (!email.empty()) {
+ person->set_email(email);
+ }
+
+ while (true) {
+ cout << "Enter a phone number (or leave blank to finish): ";
+ string number;
+ getline(cin, number);
+ if (number.empty()) {
+ break;
+ }
+
+ tutorial::Person::PhoneNumber* phone_number = person->add_phone();
+ phone_number->set_number(number);
+
+ cout << "Is this a mobile, home, or work phone? ";
+ string type;
+ getline(cin, type);
+ if (type == "mobile") {
+ phone_number->set_type(tutorial::Person::MOBILE);
+ } else if (type == "home") {
+ phone_number->set_type(tutorial::Person::HOME);
+ } else if (type == "work") {
+ phone_number->set_type(tutorial::Person::WORK);
+ } else {
+ cout << "Unknown phone type. Using default." << endl;
+ }
+ }
+}
+
+// Main function: Reads the entire address book from a file,
+// adds one person based on user input, then writes it back out to the same
+// file.
+int main(int argc, char* argv[]) {
+ // Verify that the version of the library that we linked against is
+ // compatible with the version of the headers we compiled against.
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ if (argc != 2) {
+ cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
+ return -1;
+ }
+
+ tutorial::AddressBook address_book;
+
+ {
+ // Read the existing address book.
+ fstream input(argv[1], ios::in | ios::binary);
+ if (!input) {
+ cout << argv[1] << ": File not found. Creating a new file." << endl;
+ } else if (!address_book.ParseFromIstream(&input)) {
+ cerr << "Failed to parse address book." << endl;
+ return -1;
+ }
+ }
+
+ // Add an address.
+ PromptForAddress(address_book.add_person());
+
+ {
+ // Write the new address book back to disk.
+ fstream output(argv[1], ios::out | ios::trunc | ios::binary);
+ if (!address_book.SerializeToOstream(&output)) {
+ cerr << "Failed to write address book." << endl;
+ return -1;
+ }
+ }
+
+ // Optional: Delete all global objects allocated by libprotobuf.
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return 0;
+}
diff --git a/mp/src/thirdparty/protobuf-2.3.0/examples/addressbook.proto b/mp/src/thirdparty/protobuf-2.3.0/examples/addressbook.proto
index d4cbd24c..b14829e9 100644
--- a/mp/src/thirdparty/protobuf-2.3.0/examples/addressbook.proto
+++ b/mp/src/thirdparty/protobuf-2.3.0/examples/addressbook.proto
@@ -1,30 +1,30 @@
-// See README.txt for information and build instructions.
-
-package tutorial;
-
-option java_package = "com.example.tutorial";
-option java_outer_classname = "AddressBookProtos";
-
-message Person {
- required string name = 1;
- required int32 id = 2; // Unique ID number for this person.
- optional string email = 3;
-
- enum PhoneType {
- MOBILE = 0;
- HOME = 1;
- WORK = 2;
- }
-
- message PhoneNumber {
- required string number = 1;
- optional PhoneType type = 2 [default = HOME];
- }
-
- repeated PhoneNumber phone = 4;
-}
-
-// Our address book file is just one of these.
-message AddressBook {
- repeated Person person = 1;
-}
+// See README.txt for information and build instructions.
+
+package tutorial;
+
+option java_package = "com.example.tutorial";
+option java_outer_classname = "AddressBookProtos";
+
+message Person {
+ required string name = 1;
+ required int32 id = 2; // Unique ID number for this person.
+ optional string email = 3;
+
+ enum PhoneType {
+ MOBILE = 0;
+ HOME = 1;
+ WORK = 2;
+ }
+
+ message PhoneNumber {
+ required string number = 1;
+ optional PhoneType type = 2 [default = HOME];
+ }
+
+ repeated PhoneNumber phone = 4;
+}
+
+// Our address book file is just one of these.
+message AddressBook {
+ repeated Person person = 1;
+}
diff --git a/mp/src/thirdparty/protobuf-2.3.0/examples/list_people.cc b/mp/src/thirdparty/protobuf-2.3.0/examples/list_people.cc
index 260263a0..5363152e 100644
--- a/mp/src/thirdparty/protobuf-2.3.0/examples/list_people.cc
+++ b/mp/src/thirdparty/protobuf-2.3.0/examples/list_people.cc
@@ -1,68 +1,68 @@
-// See README.txt for information and build instructions.
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include "addressbook.pb.h"
-using namespace std;
-
-// Iterates though all people in the AddressBook and prints info about them.
-void ListPeople(const tutorial::AddressBook& address_book) {
- for (int i = 0; i < address_book.person_size(); i++) {
- const tutorial::Person& person = address_book.person(i);
-
- cout << "Person ID: " << person.id() << endl;
- cout << " Name: " << person.name() << endl;
- if (person.has_email()) {
- cout << " E-mail address: " << person.email() << endl;
- }
-
- for (int j = 0; j < person.phone_size(); j++) {
- const tutorial::Person::PhoneNumber& phone_number = person.phone(j);
-
- switch (phone_number.type()) {
- case tutorial::Person::MOBILE:
- cout << " Mobile phone #: ";
- break;
- case tutorial::Person::HOME:
- cout << " Home phone #: ";
- break;
- case tutorial::Person::WORK:
- cout << " Work phone #: ";
- break;
- }
- cout << phone_number.number() << endl;
- }
- }
-}
-
-// Main function: Reads the entire address book from a file and prints all
-// the information inside.
-int main(int argc, char* argv[]) {
- // Verify that the version of the library that we linked against is
- // compatible with the version of the headers we compiled against.
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- if (argc != 2) {
- cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
- return -1;
- }
-
- tutorial::AddressBook address_book;
-
- {
- // Read the existing address book.
- fstream input(argv[1], ios::in | ios::binary);
- if (!address_book.ParseFromIstream(&input)) {
- cerr << "Failed to parse address book." << endl;
- return -1;
- }
- }
-
- ListPeople(address_book);
-
- // Optional: Delete all global objects allocated by libprotobuf.
- google::protobuf::ShutdownProtobufLibrary();
-
- return 0;
-}
+// See README.txt for information and build instructions.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "addressbook.pb.h"
+using namespace std;
+
+// Iterates though all people in the AddressBook and prints info about them.
+void ListPeople(const tutorial::AddressBook& address_book) {
+ for (int i = 0; i < address_book.person_size(); i++) {
+ const tutorial::Person& person = address_book.person(i);
+
+ cout << "Person ID: " << person.id() << endl;
+ cout << " Name: " << person.name() << endl;
+ if (person.has_email()) {
+ cout << " E-mail address: " << person.email() << endl;
+ }
+
+ for (int j = 0; j < person.phone_size(); j++) {
+ const tutorial::Person::PhoneNumber& phone_number = person.phone(j);
+
+ switch (phone_number.type()) {
+ case tutorial::Person::MOBILE:
+ cout << " Mobile phone #: ";
+ break;
+ case tutorial::Person::HOME:
+ cout << " Home phone #: ";
+ break;
+ case tutorial::Person::WORK:
+ cout << " Work phone #: ";
+ break;
+ }
+ cout << phone_number.number() << endl;
+ }
+ }
+}
+
+// Main function: Reads the entire address book from a file and prints all
+// the information inside.
+int main(int argc, char* argv[]) {
+ // Verify that the version of the library that we linked against is
+ // compatible with the version of the headers we compiled against.
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ if (argc != 2) {
+ cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
+ return -1;
+ }
+
+ tutorial::AddressBook address_book;
+
+ {
+ // Read the existing address book.
+ fstream input(argv[1], ios::in | ios::binary);
+ if (!address_book.ParseFromIstream(&input)) {
+ cerr << "Failed to parse address book." << endl;
+ return -1;
+ }
+ }
+
+ ListPeople(address_book);
+
+ // Optional: Delete all global objects allocated by libprotobuf.
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return 0;
+}