- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List

# StringListCreator.h

    00001 /*
    00002  *  Phusion Passenger - http://www.modrails.com/
    00003  *  Copyright (c) 2010 Phusion
    00004  *
    00005  *  "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
    00006  *
    00007  *  Permission is hereby granted, free of charge, to any person obtaining a copy
    00008  *  of this software and associated documentation files (the "Software"), to deal
    00009  *  in the Software without restriction, including without limitation the rights
    00010  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00011  *  copies of the Software, and to permit persons to whom the Software is
    00012  *  furnished to do so, subject to the following conditions:
    00013  *
    00014  *  The above copyright notice and this permission notice shall be included in
    00015  *  all copies or substantial portions of the Software.
    00016  *
    00017  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00018  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00019  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00020  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00021  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00022  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00023  *  THE SOFTWARE.
    00024  */
    00025 #ifndef _PASSENGER_STRING_LIST_CREATOR_H_
    00026 #define _PASSENGER_STRING_LIST_CREATOR_H_
    00027
    00028 #include <string>
    00029 #include <vector>
    00030 #include <boost/shared_ptr.hpp>
    00031 #include "Utils.h"
    00032 #include "Utils/Base64.h"
    00033
    00034 namespace Passenger {
    00035
    00036 using namespace std;
    00037 using namespace boost;
    00038
    00039 typedef vector<string> StringList;
    00040 typedef shared_ptr<StringList> StringListPtr;
    00041
    00042
    00043 class StringListCreator {
    00044 public:
    00045         virtual ~StringListCreator() {}
    00046
    00047         /** May throw arbitrary exceptions. */
    00048         virtual const StringListPtr getItems() const = 0;
    00049 };
    00050
    00051 typedef shared_ptr<StringListCreator> StringListCreatorPtr;
    00052
    00053 class SimpleStringListCreator: public StringListCreator {
    00054 public:
    00055         StringListPtr items;
    00056
    00057         SimpleStringListCreator() {
    00058                 items = ptr(new StringList());
    00059         }
    00060
    00061         SimpleStringListCreator(const StaticString &data) {
    00062                 items = ptr(new StringList());
    00063                 string buffer = Base64::decode(data);
    00064                 if (!buffer.empty()) {
    00065                         string::size_type start = 0, pos;
    00066                         const string &const_buffer(buffer);
    00067                         while ((pos = const_buffer.find('\0', start)) != string::npos) {
    00068                                 items->push_back(const_buffer.substr(start, pos - start));
    00069                                 start = pos + 1;
    00070                         }
    00071                 }
    00072         }
    00073
    00074         virtual const StringListPtr getItems() const {
    00075                 return items;
    00076         }
    00077 };
    00078
    00079 typedef shared_ptr<SimpleStringListCreator> SimpleStringListCreatorPtr;
    00080
    00081 } // namespace Passenger
    00082
    00083 #endif /* _PASSENGER_STRING_LIST_CREATOR_H_ */