Doxygen changes for ANA: Fix an image issue...
...and only include in the doxygen documentation the code in ana/api. Documented the serializer module of ANA and inserted a method.
This commit is contained in:
parent
3e316125db
commit
87e1938367
4 changed files with 171 additions and 14 deletions
|
@ -4,7 +4,7 @@ PROJECT_NAME = ana
|
|||
|
||||
PROJECT_NUMBER =
|
||||
|
||||
OUTPUT_DIRECTORY = code
|
||||
OUTPUT_DIRECTORY = doc
|
||||
|
||||
CREATE_SUBDIRS = YES
|
||||
|
||||
|
@ -14,21 +14,21 @@ BRIEF_MEMBER_DESC = YES
|
|||
|
||||
REPEAT_BRIEF = YES
|
||||
|
||||
ABBREVIATE_BRIEF =
|
||||
ABBREVIATE_BRIEF =
|
||||
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
INLINE_INHERITED_MEMB = YES
|
||||
|
||||
FULL_PATH_NAMES = YES
|
||||
|
||||
STRIP_FROM_PATH = src/ana
|
||||
STRIP_FROM_PATH = src/ana/api
|
||||
|
||||
STRIP_FROM_INC_PATH =
|
||||
STRIP_FROM_INC_PATH =
|
||||
|
||||
SHORT_NAMES = NO
|
||||
|
||||
JAVADOC_AUTOBRIEF = YES
|
||||
JAVADOC_AUTOBRIEF = YES
|
||||
|
||||
QT_AUTOBRIEF = NO
|
||||
|
||||
|
@ -40,7 +40,7 @@ SEPARATE_MEMBER_PAGES = NO
|
|||
|
||||
TAB_SIZE = 4
|
||||
|
||||
ALIASES =
|
||||
ALIASES =
|
||||
|
||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
||||
|
||||
|
@ -175,7 +175,7 @@ WARN_FORMAT = "$file:$line: $text"
|
|||
|
||||
WARN_LOGFILE =
|
||||
|
||||
INPUT = ../../src/ana
|
||||
INPUT = ../../src/ana/api
|
||||
|
||||
|
||||
INPUT_ENCODING = UTF-8
|
||||
|
@ -553,10 +553,10 @@ DIRECTORY_GRAPH = YES
|
|||
DOT_IMAGE_FORMAT = png
|
||||
|
||||
|
||||
DOT_PATH =
|
||||
DOT_PATH =
|
||||
|
||||
|
||||
DOTFILE_DIRS =
|
||||
DOTFILE_DIRS =
|
||||
|
||||
|
||||
DOT_GRAPH_MAX_NODES = 50
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
*
|
||||
* ana is an API to develop simple server and client applications.
|
||||
*
|
||||
* @image html ana.png
|
||||
* @image html logo.svg
|
||||
*
|
||||
* This project is being carried out as part of a Google Summer of Code 2010
|
||||
* project to reimplement <A HREF="http://wesnoth.org"> Wesnoth </A>'s stack.
|
||||
|
|
|
@ -42,6 +42,9 @@
|
|||
|
||||
namespace ana
|
||||
{
|
||||
/**
|
||||
* Module for object serialization and Marshalling.
|
||||
*/
|
||||
namespace serializer
|
||||
{
|
||||
template <class T>
|
||||
|
@ -69,6 +72,15 @@ namespace ana
|
|||
template <class K, class D>
|
||||
struct template_is_container< std::multimap<K,D> > { enum { value = 1 }; };
|
||||
|
||||
/**
|
||||
* Output stream serialization. This class provides stream functionality to serialize
|
||||
* objects in a way similar to that of std::cout or std::ostringstream.
|
||||
*
|
||||
* Extracted from MiLi (mili.googlecode.com).
|
||||
*
|
||||
* An extensive example of its usage can be seen in:
|
||||
* http://code.google.com/p/mili/source/browse/trunk/example_binary-streams.cpp
|
||||
*/
|
||||
class bostream
|
||||
{
|
||||
private:
|
||||
|
@ -77,11 +89,19 @@ namespace ana
|
|||
template<class T, bool IsContainer> friend struct _inserter_helper;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Standard constructor.
|
||||
*/
|
||||
bostream() :
|
||||
_s()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert any object to the stream.
|
||||
*
|
||||
* @param x : A copy of the object being inserted.
|
||||
*/
|
||||
template <class T>
|
||||
bostream& operator<< (T x)
|
||||
{
|
||||
|
@ -89,7 +109,9 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/* Inserting a string inserts its size first. */
|
||||
/**
|
||||
* Insert a string to the stream.
|
||||
*/
|
||||
bostream& operator<< (const std::string& s)
|
||||
{
|
||||
(*this) << uint32_t( s.size() );
|
||||
|
@ -97,6 +119,9 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a vector of elements.
|
||||
*/
|
||||
template <class Other>
|
||||
bostream& operator<< (const std::vector<Other>& vec)
|
||||
{
|
||||
|
@ -108,50 +133,83 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/** Insert a literal string. */
|
||||
bostream& operator<< (const char* cs)
|
||||
{
|
||||
const std::string s(cs);
|
||||
return operator<< (s);
|
||||
}
|
||||
|
||||
/** Obtain the string representing the stream. */
|
||||
const std::string& str() const
|
||||
{
|
||||
return _s;
|
||||
}
|
||||
|
||||
/** Clear the stream. Enables the user to use it several times. */
|
||||
void clear()
|
||||
{
|
||||
_s.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** The representation of the stream in memory. */
|
||||
std::string _s;
|
||||
};
|
||||
|
||||
/**
|
||||
* Input stream serialization. This class provides stream functionality to serialize
|
||||
* objects in a way similar to that of std::cin or std::istringstream.
|
||||
*
|
||||
* Extracted from MiLi (mili.googlecode.com).
|
||||
*
|
||||
* An extensive example of its usage can be seen in:
|
||||
* http://code.google.com/p/mili/source/browse/trunk/example_binary-streams.cpp
|
||||
*/
|
||||
class bistream
|
||||
{
|
||||
private:
|
||||
template<class T> friend class container_reader;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct a new input stream object using a string representing a binary stream
|
||||
* as input.
|
||||
*/
|
||||
bistream(const std::string& str) :
|
||||
_s(str),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new input stream object, but with no data.
|
||||
*/
|
||||
bistream() :
|
||||
_s(),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the representation binary string.
|
||||
*
|
||||
* @param str : The new binary stream representation string.
|
||||
*/
|
||||
void str(const std::string& str)
|
||||
{
|
||||
_pos = 0;
|
||||
_s = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an element.
|
||||
*
|
||||
* @param x : A reference to the element you are reading into.
|
||||
*
|
||||
* @pre : The remaining input stream holds enough data to read the element.
|
||||
*/
|
||||
template <class T>
|
||||
bistream& operator >> (T& x)
|
||||
{
|
||||
|
@ -160,6 +218,14 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a string.
|
||||
*
|
||||
* @param str : A reference to the string you are reading into.
|
||||
*
|
||||
* @pre : The stream is situated in a position holding a 32 bit unsigned integer
|
||||
* and then at least this very number of bytes remain.
|
||||
*/
|
||||
bistream& operator >> (std::string& str)
|
||||
{
|
||||
uint32_t size;
|
||||
|
@ -170,6 +236,14 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a vector.
|
||||
*
|
||||
* @param vec : A reference to the vector you are reading into.
|
||||
*
|
||||
* @pre : The stream is situated in a position holding a 32 bit unsigned integer
|
||||
* and then at least this very number of elements remain.
|
||||
*/
|
||||
template <class Other>
|
||||
bistream& operator>> (std::vector<Other>& vec)
|
||||
{
|
||||
|
@ -183,6 +257,7 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/** Clear the input stream. */
|
||||
void clear()
|
||||
{
|
||||
_s.clear();
|
||||
|
@ -190,14 +265,33 @@ namespace ana
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
/** The string representing the input stream. */
|
||||
std::string _s;
|
||||
|
||||
/** The position the stream is reading from. */
|
||||
std::size_t _pos;
|
||||
};
|
||||
|
||||
/**
|
||||
* A helper class to insert containers from single elements. Use this when you know that
|
||||
* the data will later be read into a vector or some other container but you don't have
|
||||
* such a container for insertion, you want to create it on the go.
|
||||
*
|
||||
* @param T : The type of the elements in the container.
|
||||
*/
|
||||
template<class T>
|
||||
class container_writer
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param size : The amount of elements you will write.
|
||||
* @param bos : A reference to the output stream where you will create the
|
||||
* container.
|
||||
*/
|
||||
container_writer( size_t size, bostream& bos) :
|
||||
_elements_left( size ),
|
||||
_bos( bos )
|
||||
|
@ -205,6 +299,9 @@ namespace ana
|
|||
_bos << uint32_t( size );
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an element.
|
||||
*/
|
||||
container_writer& operator<<(T element)
|
||||
{
|
||||
assert( _elements_left > 0 );
|
||||
|
@ -215,20 +312,42 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default destructor.
|
||||
*
|
||||
* @pre : The elements inserted equals the amount of elements that were promised
|
||||
* to be inserted at the time of creation (size parameter.)
|
||||
*/
|
||||
~container_writer()
|
||||
{
|
||||
if ( _elements_left != 0 )
|
||||
throw/* std::runtime_error*/("More elements were expected to be written.");
|
||||
}
|
||||
private:
|
||||
|
||||
/** The amount of elements you have yet to insert. */
|
||||
size_t _elements_left;
|
||||
|
||||
/** A reference to the output stream. */
|
||||
bostream& _bos;
|
||||
};
|
||||
|
||||
/**
|
||||
* A helper class to read from containers one by one. Use this when you want to read
|
||||
* something inserted as a container one by one, you can also use it to know how many
|
||||
* elements were inserted.
|
||||
*
|
||||
* @param T : The type of the elements in the container.
|
||||
*/
|
||||
template<class T>
|
||||
class container_reader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Standard constructor.
|
||||
*
|
||||
* @param bis : The input stream holding the data.
|
||||
*/
|
||||
container_reader( bistream& bis) :
|
||||
_elements_left( 0 ),
|
||||
_bis( bis )
|
||||
|
@ -236,6 +355,9 @@ namespace ana
|
|||
_bis >> _elements_left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an element.
|
||||
*/
|
||||
container_reader& operator>>(T& element)
|
||||
{
|
||||
assert( _elements_left > 0 );
|
||||
|
@ -246,6 +368,17 @@ namespace ana
|
|||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip a given amount of elements, default: 1.
|
||||
*
|
||||
* Examples:
|
||||
* - skip();
|
||||
* - skip(10);
|
||||
*
|
||||
* @param elements : The amount of elements you want to skip. Default: 1.
|
||||
*
|
||||
* @pre : At least the amount of elements you want to skip remain.
|
||||
*/
|
||||
void skip(size_t elements = 1)
|
||||
{
|
||||
if ( elements > _elements_left )
|
||||
|
@ -259,12 +392,27 @@ namespace ana
|
|||
throw("Too much mas skipped.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that you have finished reading. It is the same as skipping the amount
|
||||
* of elements left.
|
||||
*/
|
||||
void finished()
|
||||
{
|
||||
skip( _elements_left );
|
||||
_elements_left = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of elements that still haven't been read from the container.
|
||||
*/
|
||||
size_t elements_left() const
|
||||
{
|
||||
return _elements_left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard destructor. Finishes the reading process if necessary.
|
||||
*/
|
||||
~container_reader()
|
||||
{
|
||||
if ( _elements_left != 0 )
|
||||
|
@ -272,7 +420,11 @@ namespace ana
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
/** The amount of elements that still haven't been read from the container. */
|
||||
size_t _elements_left;
|
||||
|
||||
/** A reference to the input stream. */
|
||||
bistream& _bis;
|
||||
};
|
||||
|
||||
|
|
|
@ -609,6 +609,8 @@ ana::net_id ana_network_manager::create_server( )
|
|||
|
||||
network::connection ana_network_manager::create_client_and_connect(std::string host, int port)
|
||||
{
|
||||
ana::net_id new_client_id;
|
||||
|
||||
try
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
@ -619,6 +621,8 @@ network::connection ana_network_manager::create_client_and_connect(std::string h
|
|||
|
||||
ana::client* const client = new_component->client();
|
||||
|
||||
new_client_id = client->id();
|
||||
|
||||
ana_connect_handler handler;
|
||||
|
||||
client->set_raw_data_mode();
|
||||
|
@ -632,7 +636,7 @@ network::connection ana_network_manager::create_client_and_connect(std::string h
|
|||
if( handler.error() )
|
||||
{
|
||||
network::disconnect( client->id() );
|
||||
return 0;
|
||||
throw network::error(_("Could not connect to host"), client->id() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -649,7 +653,7 @@ network::connection ana_network_manager::create_client_and_connect(std::string h
|
|||
send_handler.wait_completion();
|
||||
|
||||
if ( send_handler.error() )
|
||||
return 0;
|
||||
throw network::error(_("Could not connect to host"), client->id() );
|
||||
else
|
||||
{
|
||||
uint32_t my_id;
|
||||
|
@ -671,6 +675,7 @@ network::connection ana_network_manager::create_client_and_connect(std::string h
|
|||
}
|
||||
catch( const std::exception& e )
|
||||
{
|
||||
throw network::error(_("Could not connect to host"), new_client_id );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue